Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
6 Points
19 Posts
Jun 23, 2008 02:37 PM|LINK
If you don't want to write the HTML you can do something like this Controller: Dictionary<string,string> states = new Dictionary<string,string>(); states.Add("NY", "New York"); states.Add("PA", "Pennsylvania"); .... ViewData["States"] = new SelectList(states, "Key", "Value", "NY"); return View("Index"); //// Page.aspx <%= Html.DropDownList("States") %>
AlexBecker
Member
6 Points
19 Posts
Re: Drop Down List NOT from datasource
Jun 23, 2008 02:37 PM|LINK
If you don't want to write the HTML you can do something like this
Controller:
Dictionary<string,string> states = new Dictionary<string,string>();
states.Add("NY", "New York");
states.Add("PA", "Pennsylvania");
....
ViewData["States"] = new SelectList(states, "Key", "Value", "NY");
return View("Index");
////
Page.aspx
<%= Html.DropDownList("States") %>