Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can declare your model as</p> <pre><code>public class TestModel { public SchduleEnum SelectedScheduleEnum { get; set; } public ProgramCatagory SelectedProgram { get; set; } public IEnumerable&lt;SelectListItem&gt; ScheduleEnums { get { return this.GetScheduleEnums(); } } public IEnumerable&lt;SelectListItem&gt; SelectedPrograms { get { return this.GetSelectedPrograms(); } } private IEnumerable&lt;SelectListItem&gt; GetSelectedPrograms() { List&lt;SelectListItem&gt; items=new List&lt;SelectListItem&gt;(); Enum.GetNames(typeof(ProgramCatagory)).ToList().ForEach(s=&gt;{ bool IsSelected=((int)Enum.Parse(typeof(ProgramCatagory), s)).Equals((int)SelectedScheduleEnum); if(IsSelected) this.SelectedProgram = (ProgramCatagory)Enum.Parse(typeof(ProgramCatagory), s); items.Add(new SelectListItem() { Text = s, Value = s, Selected = IsSelected }); }); return items; } private IEnumerable&lt;SelectListItem&gt; GetScheduleEnums() { List&lt;SelectListItem&gt; items = new List&lt;SelectListItem&gt;(); Enum.GetNames(typeof(SchduleEnum)).ToList().ForEach(s =&gt; { bool IsSelected = ((int)Enum.Parse(typeof(SchduleEnum),s)).Equals((int)SelectedProgram); if (IsSelected) this.SelectedScheduleEnum = (SchduleEnum)Enum.Parse(typeof(SchduleEnum), s); items.Add(new SelectListItem() { Text = s, Value = s, Selected = IsSelected }); }); return items; } } public enum SchduleEnum { Daily = 0, Weekly, Monthly }; public enum ProgramCatagory { News=0 , Movie, Discussion }; </code></pre> <p>In The controller,</p> <pre><code>public ActionResult Index() { TestModel model = new TestModel(); model.SelectedScheduleEnum = SchduleEnum.Monthly; return View(model); } </code></pre> <p>In the view you can call like,</p> <pre><code>&lt;%:Html.DropDownListFor(m=&gt;m.SelectedProgram,Model.SelectedPrograms)%&gt; &lt;%:Html.DropDownListFor(m=&gt;m.SelectedScheduleEnum,Model.ScheduleEnums) %&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload