从Checkbox获取价值

时间:2010-01-09 21:16:13

标签: asp.net-mvc

您好我无法预先显示屏幕上所有复选框的值。 让我解释一下,我有5个复选框,例如2是增强而不是其他我想要一个包含所有5个复选框的数组,包括2个真和其他假 有人可以帮助我。

与此同时我尝试做另一个我创建了一个类

的系统
public class PresenzaAO    
        (    
           public List <Presenti> listapresenti = new List <Presenti> ();    
            public string conteggiototale (get;)    
            public long idalunno (get;)    
           public string radio (get;)    
       )    

        public class Present    
        (    
           public string presents{get;set;}    
        )   
and then in the view I created this: 



<% Using (Html.BeginForm (ModificaPresenzaAlunno "," Presence ", FormMethod.Post))    
       (%>    
    <% = Html.Hidden ( "conteggiototale" Viewdata [ "conteggiototale"])%>    
   <% = Html.Hidden (idalunno "Viewdata [" student "])%>    
    <table>    
        <tr>    
            <td>    
                <% = Html.Encode (nomealunno)%>    
            </ td>    
            <td>    
                <% = Html.Encode (cognomealunno)%>    
            </ td>    
            <%    
                if (Viewdata [ "conteggio_presenze"]. ToString () == Viewdata ["conteggiototale"]. ToString ())    
               (%>    
           <td>    
               Absent    
                <input type = "radio" name = "radio" checked = "checked" id = "assente_"    
                    onclick = "getassentemod (<% = Viewdata [" student "]%>, 0);" value = "true_assente" />    
                  This    
                <input type = "radio" name = "radio" id = "presente_" value = "false_presente"    
                    onclick = "getassentemod (<% = Viewdata [" student "]%>, 0);" />    
           </ td>    
            <% Int i = 0;%>    
            <% Foreach (var p in (List <PresenzaAlunnoOra>) Viewdata [ "presenze_alunno"])    
               (    

                   i + = 1;    

            %>    
           <td>    
                <input type = "checkbox" id = "check_ <% = Viewdata [" student "] %><%= i%>" value ="<%= i%> "name =" Present "    
                   onclick = "modificapresenzaalunno (this);" />    
           </ td>    
            <%)%>    
            <%)    
                else    
                (%>    
            <td>    
                Absent    
                <input type = "radio" value = "false_assente" name = "radio" id = "assente_ <% = Viewdata [" student "]%>"    
                    onclick = "getassentemod (<% = Viewdata [" student "]%>, 0);" />    
                  This    
                <input type = "radio" value = "true_presente" name = "radio" checked = "checked" id = "presente_ <% = Viewdata [" student "]%>"    
                    onclick = "getpresentemod (<% = Viewdata [" student "]%>, 0);" />    
            </ td>    
            <% Int i = 0;%>    
            <%    
                foreach (var p in (List <PresenzaAlunnoOra>) Viewdata [ "presenze_alunno"])    
                (    
                    i + = 1;    
                    if (p.presente == true)    
                    (    
            %>    
            <td>    
                <input type = "checkbox" id = "check_ <% = Viewdata [" student "] %>,<%= i%>" name = "Present"    
                    checked = "checked" value ="<%= i%> "onclick =" modificapresenzaalunno (this); "/>    
            </ td>    
            <%)    

                    else    
                    (%>    
            <td>    
                <input type = "checkbox" id = "check_ <% = Viewdata [" pupil "]%>,<%= i%> "value ="<%= i%>" name = "Present"    
                    onclick = "modificapresenzaalunno (this);" />    
            </ td>    
            <%)%>    
            <%)%>    
            <%)%>    
        </ tr>    
    </ table>    
    <input type="submit" id="btnupdatealunni" value="modifica presenze" />    
    <%)%>    
</ asp: Content>

将控制器参数PresenzaAO存在

我读了除复选框

之外的所有参数

1 个答案:

答案 0 :(得分:0)

不,它不包含空格,但我注意到在复选框名称中发布的示例中缺少某些内容 说复选框的名称应如下所示:

<input type = "checkbox" id = "check_ <% = Viewdata [" pupil "]%>,<%= i%> "value ="<%= i%>" name = "Present [<% = i% >].presents"
                    onclick = "modificapresenzaalunno (this);" />

但我甚至不工作