我正在使用razor和javascript使用ASP.net MVC4。
我加载我的观点如下: 当从数据库中检索数据时没有检查radiobutton的值时,radiobutton是空的,我该如何解决这个问题?在文本框中的值被恢复为radiobutton no。
<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>
答案 0 :(得分:1)
如果您不能使用for helper将其绑定到您的模型,那么您需要在该字段上添加一个唯一的名称,然后您可以使用
获取控制器上的值Request.Form["RadioName"].ToString()