我有一张桌子,他们的记录的结尾是购买按钮。如何将foreach中的产品Id发送给控制器。
@foreach(var model in Model)
{
<tr>
<td>@model.Title</td>
<td>@model.Counts</td>
<td>@model.Price</td>
<td> <button class="btn btn-warning">Buy</button> </td>
</tr>
}
发布于 2018-12-13 09:57:28
您可以将@Html.ActionLink()
或HTML锚标签与@Url.Action()
帮助程序一起使用,以发送模型的Id
属性,并将其样式设置为类似按钮的样式:
锚定标记版本
<a href="@Url.Action("Buy", "ControllerName", new { id = model.Id })" class="btn btn-warning" role="button">Buy</a>
ActionLink帮助程序版本
@Html.ActionLink("Buy", "Buy", "ControllerName", new { id = model.Id }, new { @class = "btn btn-warning", @role = "button" })
两种方法都会产生相同的结果(X
是指传入的ID值):
<a href="/ControllerName/Buy?id=X" class="btn btn-warning" role="button">Buy</a>
https://stackoverflow.com/questions/53746349
复制相似问题