-1
這是對數量的計算asp.net的MVC Razor視圖設計*表的特定行的價格它的工作完美的,但問題是計算出的值不隱藏字段存儲。 screen shot of outputhiddenfield值使用jQuery設置它的回報率[目標對象]
@<table id="tbl" class="table table-striped table-hover">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@for (var i = 0; i < Model.ListProducts.Count(); i++)
{
var pro = Model.ListProducts[i];
<tr>
<td>@pro.ShortName @pro.SizeDetails.Size</td>
<td>@Html.HiddenFor(m => m.ListProducts[i].SizeDetails.SID)
@Html.HiddenFor(m => m.ListProducts[i].PID)
@Html.TextBoxFor(m => m.ListProducts[i].Qty, new { @class = "qty form-control", @style = "width:100px;display:inline;" })</td>
<td>
<i class="fa fa-inr"></i>
<label class="">
@if (@pro.SizeDetails.DistPrice != null && @pro.SizeDetails.DistPrice != 0)
{
@pro.SizeDetails.DistPrice
}
else
{
@pro.SizeDetails.MRP
}
</label>
<input type="hidden" value="@if (@pro.SizeDetails.DistPrice != null && @pro.SizeDetails.DistPrice != 0)
{@pro.SizeDetails.DistPrice}
else
{@pro.SizeDetails.MRP}" class="price"/>
// @Html.TextBoxFor(m => m.ListProducts[i].finalPrice, new { @id="txtP"})
</td>
<td class="total">
</td>
@Html.HiddenFor(m => m.ListProducts[i].Price, new { @class = "total" ,@id="hdnTot"})
</tr>
}
</tbody>
</table>
腳本
//$('body').on('blur', '.qty, .price', function(e) {
$('.qty, .price').on('blur', function (e) {
debugger;
// Get Parent ROW
var row = $(this).closest('tr');
var qty = $('.qty', row),
pr = $('.price', row),
tot = $('.total', row);
$('#hdnTot').val(tot);
quantity = parseFloat(qty.val());
price = parseFloat(pr.val());
if (!isNaN(quantity) && !isNaN(price)) {
tot.text((quantity * price).toFixed(2));
}
});
你的問題並不能幫助我們花了多少錢,你會遇到什麼問題? – madalinivascu
3500.00 –
使用字,如:我這樣做,結果是這和錯誤是這樣的,等你可以做到! – madalinivascu