我目前有这样的视图:
@using (Html.BeginForm("Compare", "Carousel", FormMethod.Post))
{
@foreach (var product in Model.Products)
{
<tr>
<td>@product.Provider.Name</td>
<td>£@Math.Round(product.MonthlyPremium, 2, MidpointRounding.AwayFromZero)</td>
<td>@Html.ActionLink("More Details", "MoreDetails", new { id = product.ProductId })</td>
<td><button name="compare" value="@product.ProductId">Compare</button</td>
</tr>
}
}
控制器:
[HttpPost]
public ActionResult Compare(ProductsWithDetailModel model) // This is a guess, Model may not persist?
{
// Code here
return View("Index", model);
}
我真正想要的是,当单击按钮时,将调用控制器并将已选择的产品(单击的按钮)添加到项目列表中。
我如何真正找出在控制器中单击了哪个按钮?为什么我在网上找不到任何以前做过的教程,肯定是它的基本功能?还是我接近它错了?