I have a model like the following one:
public class TestModel{
public IList<Field> Fields {get; set;}
}
public class Field{
public String Key {get; set;}
public String Value {get; set;}
}
How would I have to make the corresponding view form, to get the Model correctly binded after the post request? The user should be able to select the various Fields with checkboxes and the Model should contain the selected ones.
In the Action method below, the Model’s members are null.
public ActionResult XY(TestModel model){[...]}
i have added to your model a
Selectedpropertyi have added an
EditorTemplateto display a singleFieldwhat will happen now when you submit, all the items will be send you can then filter all the item that have a property of
Selected=trueThe Model
The Controller [TestController.cs]
The View [/Views/Test/Index.cshtml]
The Editor Template [/Views/Test/EditorTemplates/Field.cshtml]