asp.net mvc - How to map a list of checkboxes options to a model first class? -


i have list of options in web form:

enter image description here

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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -