asp.net mvc - How to map a list of checkboxes options to a model first class? -
i have list of options in web form:
and want work model-first. i'm noob mvc , model-first, don't know how better represent in model class.
should make 1 attribuite each item? or should make array each position 1 option (maybe using enums
)?
public bool[] comportamento { get; set; } // or public comportamento[] comportamento { get; set; } // or public bool manso { get; set; } public bool arisco { get; set; } ...
you should have class compartamentoviewmodel
looks this:
public class compartamentoviewmodel { public int id { get; set; } public string description { get; set; } }
then, in main view model:
public class myviewmodel { // list of objects view public list<compartamentoviewmodel> compartamentos { get; set; } // list of ints retrieve selected values public list<int> selectedcompartamentos { get; set; } }
in view, use description text , id value. in post, populate selectedcompartamentos
list of selected ids.
disclaimer: have no idea how pluralise "compartamento."
Comments
Post a Comment