我在 MVC 中有表格布局(见下面的代码),在每个表格行上我都有一个提交按钮。每个提交按钮发布到相同的控制器方法“TableSample”。如何捕获选定的行 id 并发布它?
public class TableSample
{
public string Property1 { get; set; }
public string Property2 { get; set; }
public int Property3 { get; set; }
public List<Things> Things;
}
@Html.TextBoxFor(m => m.Property1)
@Html.TextBoxFor(m => m.Property2)
@Html.TextBoxFor(m => m.Property3)
<table>
<tbody>
@foreach (var thing in Model.Things)
{
<tr>
<td>@thing.ID</td>
<td>@thing.Name</td>
<td><input type="submit" value="Select" name="Command" /></td>
</tr>
}
</tbody>
</table>
[HttpPost]
public ActionResult TableSample(TableSample sample, string Command)
{
if (Command == "Select")
{
//How to capture selected row ID?
}
if (Command == "Other")
{
}
}