Asp.net MVC 单选按钮检索所选数据



我正在使用带有 razor 和 javascript 的 ASP.net MVC4。

加载我的观点如下:当从数据库中检索数据不检查单选按钮的值时,单选按钮为空,如何解决此问题?这些值在文本框中恢复单选按钮编号。

    <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>

如果您不能使用 for helper 将其绑定到您的模型,那么您需要在字段上放置一个唯一的名称,然后您可以使用

Request.Form["RadioName"].ToString()

最新更新