【发布时间】:2013-01-16 16:36:49
【问题描述】:
我通过为每种产品动态构建了一个“购买产品”页面。每个产品都有一个“添加到购物篮”按钮,通过将pID 作为按钮name 属性来区分每个产品。我现在想在回发时在我的控制器中获取name 属性的值。不知道该怎么做:
查看:
@foreach (Ecommerce.Models.HomeModels.Product product in Model)
{
using (Html.BeginForm())
{
@Html.Label(product.Name);
<br />
@Html.Label(product.Description);
<br />
@Html.Label(product.UnitPrice.ToString());
<p></p>
<input name="@product.ID" type="submit" value="Add to Basket" />
}
}
控制器:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult BuyProducts(string button)
{
}
【问题讨论】:
标签: button razor asp.net-mvc-4 postback name-attribute