【发布时间】:2019-03-24 17:47:19
【问题描述】:
我有一个显示客户 ID、客户名称和单选按钮循环的表格。我正在尝试根据我的表格上给出的选项链接登录的用户。
电子邮件:test@gmail.com
客户 ID |客户名称 |选择用户
1234 |测试 1 |单选按钮(选中)
2345 |测试 2 |单选按钮
我想要的是,如果选中单选按钮(即 custId:1234),我想获取该 CustID。
这是我的代码:
控制器
public ActionResult AddCustomerLinkToDB(string IsSeleted)
{
string selectedCustomer = IsSeleted;
return View();
}
cshtml
@using (Html.BeginForm("AddCustomerLinkToDB", "Admin", FormMethod.Post))
{
<table class="table table-bordered table-hover">
<tr>
<th>Customer ID</th>
<th>Customer Name</th>
<th>Select this user</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.Id</td>
<td>@item.Name</td>
<td>@Html.RadioButton("IsSelected", new { id = item.Id })</td>
</tr>
}
</table>
}
【问题讨论】:
-
IsSelected不是IsSeleted -
@StephenMuecke 嘿,斯蒂芬,很好,但不幸的是,它没有用。我仍然是空的。
-
假设方法是
[HttpPost],它将正常工作 -
@StephenMuecke 我做了仔细检查,我的方法是 [HttpPost]
标签: asp.net-mvc razor radio-button