Asp.net MVC单选按钮检索所选数据 [英] Asp.net mvc radiobutton retrieve selected data

查看:85
本文介绍了Asp.net MVC单选按钮检索所选数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与ASP.net MVC4剃刀和JavaScript。

我打开我的看法如下:
当检索数据库中的数据不检查单选按钮的值,则单选按钮是空的,我怎样才能解决这个问题呢?该值是在文本框被回收的单选按钮没有。

 <表>
    &所述; TR>
        <第i单方面前腰< /第i
        百分位方式>&斜面LT; /第i
        <第i布埃诺< /第i
        <第i个;定期与LT; /第i
        <第i Deficiente< /第i
        <第i Observaciones< /第i
    < / TR>
    @ {INT numitem = 0;}
    @for(VAR I = 0; I< ViewBag.DatosExtFrontal.Count;我++)
    {
        &所述; TR>
        < TD> @ ViewBag.DatosExtFrontal [I] .cprp_descripcion< / TD>
        < TD> @ Html.TextBox(的String.Format(txtpieza {0},numitem),(INT)ViewBag.DatosExtFrontal [I] .piv_cantidad,新{ID =的String.Format(txtpieza {0}, ViewBag.DatosExtFrontal [I] .cprp_idparte pre.ToString()),风格=宽度:25px的;文本对齐:权利;的onkeyup =checkInt(本),sololectura = FALSE})LT; / TD>
        < TD类=TD-中心>
            @ Html.RadioButton(的String.Format(rbtestado {0},numitem),B,新{ID =的String.Format(B {0},ViewBag.DatosExtFrontal [I] .cprp_idparte pre的ToString()),sololectura = FALSE})
        < / TD>
        < TD类=TD-中心>
            @ Html.RadioButton(的String.Format(rbtestado {0},numitem),R,新{ID =的String.Format(R {0},ViewBag.DatosExtFrontal [I] .cprp_idparte pre的ToString()),sololectura = FALSE})
        < / TD>
        < TD类=TD-中心>
            @ Html.RadioButton(的String.Format(rbtestado {0},numitem),D,新{ID =的String.Format(D {0},ViewBag.DatosExtFrontal [I] .cprp_idparte pre的ToString()),sololectura = FALSE})
        < / TD>
        < TD> @ Html.TextBox(的String.Format(txtobservacion {0},numitem),(串)ViewBag.DatosExtFrontal [I] .piv_observacion,新{ID =的String.Format(txtobservacion {0}, ViewBag.DatosExtFrontal [I] .cprp_idparte pre.ToString()),风格=宽度:150像素;sololectura = FALSE})LT; / TD>
        &所述; TD>
        @ {
            字符串IdParte pre =的String.Format({0},numitem);
            字符串单方面pre =的String.Format({0}(INT)ViewBag.DatosExtFrontal [I] .cprp_idparte pre);
            numitem ++;
        }
        <输入ID =@ IdParte pre型=隐藏的名字=@单方面preVALUE =@单方面pre/>
        < / TD>
        < / TR>    }
    < /表>


解决方案

如果您不能使用的助手将它与你的模型,那么你将需要把一个独特的名字在球场上,然后就可以得到使用控制器上的值

 的Request.Form [RadioName]。的ToString()

I'm working with ASP.net MVC4 with razor and javascript.

I load my view as follow: When Retrieve data from database not check the values ​​of radiobutton, the radiobutton is empty, How I can resolve this problem? the values ​​is in the Textbox are recovered the 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>

解决方案

if you can't use a for helper to tie it to your model then you will need to put a unique name on the field and then you can get the value on your controller using

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

这篇关于Asp.net MVC单选按钮检索所选数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆