When I check both of the checkboxes, I get "1". When I first look at the checkbox, I get "1" when I only check the second checkbox, I get "false" Why is it? Moreover, how do I get to post other checkboxes (or at all) for posting? The code below and resulting HTML
@model InspectionWebFormsMVC.ViewModels.CtrlInputDataModel @ {var DDV = new selectList (Model.RowCtrl.DefaultValues, "value", "label"). Switch (Model.RowCtrl.Type) {case "box": foreach (DDV bridesmaid SLI) {@ Html.LabelFor (blah = & gt; blah.InputtedData in, sli.Text) bool isChecked = false; String atrich = "check"; If (Model.InputtedData == sli.Value) {ischecked = true; @html Checkbox ("Input Data" is checked, new {@value = sli.Value, @checked = attr checked}) else {ischecked = false; @ Html.CheckBox ( "InputtedData", isChecked, new {@value = sli.Value})}} @ Html.HiddenFor (blah = & gt; blah.InputtedDataID) @ Html.HiddenFor (blah = & gt; blah.RowCtrl .CtrlTypeID) & lt; Br / & gt; break; }} As a result HTML: / labels & gt; Red & lt; = "SectionRows_a7d91de2-c828-4cd4-979d-783caf85ae3b__RowInput_0__InputtedData" & for gt label
& lt; & Lt; Input id = "sectionRows_a7d91de2-c828-4cd4-979d-783caf85ae3b__RowInput_0__InputtedData" name = "sectionRows [a7d91de2-c828-4cd4-979d-783caf85ae3b] Kroin input [0] Kinputted data" type = "checkbox" value = "1" / & Gt; & Lt; Input name = "sectionRows [a7d91de2-c828-4cd4-979d-783caf85ae3b] .rowInput [0] .InputtedData" type = "hidden" value = "false" /> & Lt; Super & lt; Label / label for gt; sectionRows_a7d91de2-c828-4cd4-979d-783caf85ae3b__RowInput_0__InputtedData "& gt; & Lt; Input Czech = "the Czech" id = "sectionRows_a7d91de2-c828-4cd4-979d-783caf85ae3b__RowInput_0__InputtedData" name = "sectionRows [a7d91de2-c828-4cd4-979d-783caf85ae3b] Kroin input [0] Kinputted data" type = "checkbox "Value =" 2 "/> & Lt; Input name = "sectionRows [a7d91de2-c828-4cd4-979d-783caf85ae3b] .reinput [0]. Inputed data" type = "hidden" value = "false" /> & Lt; Input data-val = "true" data-val-number = "field should be inputtedDataID number." Data-val-required = "InputDetidated field is required." Id = "sectionRows_a7d91de2-c828-4cd4-979d-783caf85ae3b__RowInput_0__InputtedDataID" name = "sectionRows [a7d91de2-c828-4cd4-979d-783caf85ae3b] .inine input [0] .InputatedDetidide" type = "hidden" value = "5" /> ; & Lt; Input data-val = "true" data-val-number = "Field CtrlTypeID must be a number." Data-val-required = "The field needs the CtrlTypeID." Id = "sectionRows_a7d91de2-c828-4cd4-979d-783caf85ae3b__RowInput_0__RowCtrl_CtrlTypeID" name = "sectionRows [a7d91de2-c828-4cd4-979d-783caf85ae3b] .inine input [0] .rowCtrl.CtrlTypeID" type = "hidden" value = "5" / & Gt;
- when multiple input elements share the same
name - When the checkbox is not checked, they do not post anything.
So when you have the checkbox first, you get "1" then everything is ignored after you do not have the first checkbox, then hidden field post " False "are
If you are wondering where the hidden areas come from, then MVC helpers make a hidden field with the same name and due to # 2 the value is false make up Checkboxes are about to represent the boolean, and so they always wanted to do right / wrong post instead of value / (anything).
Comments
Post a Comment