In my MVC4 project view See Controller Model Update: * Rated HTML * Update1: Rated HTML after the following answers by Andrea Not generating the correct name for the input Your form is the same token for all items However here you can use Note that at least IEnumerable & lt; Settings & gt; When I submit a form back to my controller to see the model, the controller method should be
IEnumerable
data is always empty.
@Emelumerable & lt; Settings & gt; @Usage (Html.BeginForm ("index", "layout", FormMethod.Post)) {@foreach (preference items in model) {@ Html.CheckBoxFor (modelItem => items.isactive, new {@value = item ) Id}} @html DisplayFor (ModelItem => Item.Net)} & lt; Input type = "submit" value = "save" /> } [
[HTTP Post] Public Action Rational Index (INIM Mereble & Lt; Settings & gt; Data) { - The actual code goes here} {Class}
& lt; Td> & Lt; Input check = "checked" data-val = "true" data-val-required = "ective field is required." Id = "item_IsActive" name = "item.IsActive" type = "checkbox" value = "13" square = "valid" & gt; & Lt; Input name = "item.isactive" type = "hidden" value = "wrong" & gt; # Of pieces & lt; / Td>
& lt; Td> & Lt; Input check = "checked" data-val = "true" data-val-required = "ective field is required." Name = "[0] .IsActive" type = "checkbox" value = "13" & gt; & Lt; Input name = "[0] .IsActive" type = "hidden" value = "false" & gt; # Of pieces & lt; / Td>
@ html.CheckBoxFor (modelItem => items.isactive, New {@value = item.Id})
item.IsActive = true (Or false). Although this approach works for priorities, but it does not work for complex types.
for
instead of
foreach : <: / P>
@model IList & lt; Settings & gt; @using (Html.BeginForm ()) {@for (int i = 0; i
IList & lt; & Gt; is required as a visual type - otherwise you can not iterate through the archive using
for
. .
No comments:
Post a Comment