【发布时间】:2015-06-01 20:12:23
【问题描述】:
我有一个观点,这是其中的一个片段:
@foreach (var item in Model.Items.ToList())
{
<tr>
<td>
<input type="checkbox" name="productIdCheckbox" value="@item.sLabel">
</td>
<td>
@Html.DisplayFor(modelItem => item.sLabel)
</td>
<td>
@Html.DisplayFor(modelItem => item.Text)
</td>
<td>
@Html.DisplayFor(modelItem => item.OEMCode)
</td>
<td>
<input type="number" name="qty" id="qty" min="1" max="1000" step="1" value="@item.Quantity" />
</td>
<td>
<input type="submit" data-url='@Url.Action("AddToCart", "Cart", new { id = item.Id, qty = // I DON'T KNOW HOW TO PASS IT HERE // })' class="addProductToCartBtn btn btn-success" value="Add to cart" />
</td>
</tr>
}
此代码调用 CartController 中的 AddToCart 方法:
$('.addProductToCartBtn').click(function (event) {
var url = $(this).data('url');
$.ajax({
url: url,
type: 'GET',
success: function (resultFrom_CartSummaryLine) {
// some logic here..
}
});
});
但我无法将 qty 输入的值传递给此方法。我该怎么做?
需要明确的是,这是 CartController 的一个方法,我想在其中传递 qty 参数的值:
public PartialViewResult AddToCart(CartModel cart, int id, int qty)
{
GetItemListProcedure_Result item = _itemRepository.GetItemByItemId(id).FirstOrDefault();
if (item != null)
{
cart.AddItem(item, qty);
}
return PartialView("_CartSummaryLine", cart);
}
【问题讨论】:
标签: razor asp.net-mvc-5