c# - Single Controller an View for multiple Models -
i new mvc , ef, have group of models represent lookup tables have same structure
public int id {get; set;} public string value {get; set;} public bool isactive {get; set;}
rather writing 1 controller , view each there way create one, defined previous selected value.
so if 2 of lookups gender , status , dropdown these values can take name of selected option , dynamically bind model
so rather having status status = new status object object = new object object has been defined selection of status in previous dropdown
it possible. there several ways achieve this. have editortemplate need display dropdown. in ~/views/shared/editortemplates/dropdown.cshtml
@model string @{ layout = null; list<selectlistitem> listitems = (list<selectlistitem>)viewbag.listitems; } // not sure syntax dropdown is, don't use them @html.selectfor(m => model, listitems)
then in view
@html.editorfor(m => m.status, "dropdown", new { listitems = mymodel.statusselectlistitems }) @html.editorfor(m => m.gender, "dropdown", new { listitems = mymodel.genderselectlistitems })
where in model have selection options:
public class mymodel { // other stuff public static list<selectlistitem> genderselectlistitems = new list<selectlistitem> { new selectlistitem{ value = "male", text = "male" }, new selectlistitem{ value = "female", text = "female" } }; // etc }
Comments
Post a Comment