【发布时间】:2014-01-07 14:48:50
【问题描述】:
我正在使用带有 razor 和 javascript 的 ASP.net MVC4。
我加载我的视图如下: 当Retrieve data from database不检查radiobutton的值时,radiobutton是空的,我该如何解决这个问题? Textbox中的值都是回收的radiobutton号。
<table>
<tr>
<th>Parte Frontal</th>
<th>Cant.</th>
<th>Bueno</th>
<th>Regular</th>
<th>Deficiente</th>
<th>Observaciones</th>
</tr>
@{int numitem = 0;}
@for (var i = 0; i < ViewBag.DatosExtFrontal.Count; i++)
{
<tr>
<td>@ViewBag.DatosExtFrontal[i].cprp_descripcion</td>
<td>@Html.TextBox(string.Format("txtpieza{0}", numitem), (int)ViewBag.DatosExtFrontal[i].piv_cantidad, new { id = string.Format("txtpieza{0}", ViewBag.DatosExtFrontal[i].cprp_idpartepre.ToString()), style = "width:25px;text-align:right;", onkeyup = "checkInt(this)", sololectura = false })</td>
<td class="td-center">
@Html.RadioButton(String.Format("rbtestado{0}", numitem), "B", new { id = string.Format("B{0}", ViewBag.DatosExtFrontal[i].cprp_idpartepre.ToString()), sololectura = false })
</td>
<td class="td-center">
@Html.RadioButton(String.Format("rbtestado{0}", numitem), "R", new { id = string.Format("R{0}", ViewBag.DatosExtFrontal[i].cprp_idpartepre.ToString()), sololectura = false })
</td>
<td class="td-center">
@Html.RadioButton(String.Format("rbtestado{0}", numitem), "D", new { id = string.Format("D{0}", ViewBag.DatosExtFrontal[i].cprp_idpartepre.ToString()), sololectura = false })
</td>
<td>@Html.TextBox(string.Format("txtobservacion{0}", numitem), (string)ViewBag.DatosExtFrontal[i].piv_observacion, new { id = string.Format("txtobservacion{0}", ViewBag.DatosExtFrontal[i].cprp_idpartepre.ToString()), style = "width:150px;", sololectura = false })</td>
<td>
@{
string IdPartePre = String.Format("{0}", numitem);
string PartePre = String.Format("{0}", (int)ViewBag.DatosExtFrontal[i].cprp_idpartepre);
numitem++;
}
<input id="@IdPartePre" type="hidden" name="@PartePre" value="@PartePre"/>
</td>
</tr>
}
</table>
【问题讨论】:
-
帮助器将值与您的模型联系起来。将单选按钮更改为 @Html.RadioButtonFor
-
检查您的控制器并使用 viewbug 显示控制器操作
-
@MattBodily 如果我使用 Html.RadioButtonFor 它,这将为我的所有单选按钮生成相同的名称,我无法选择多个单选按钮
-
@user1956570 我的控制器返回带有当前信息的 DatosExtFrontal 因为加载文本框中的值
标签: c# javascript asp.net asp.net-mvc asp.net-mvc-4