I’ve got two DropDownLists within an mvc 3 based site, ‘teams’ and ‘users’ :
Select a case worker :
@Html.DropDownList("Teams", "-- Select A Team --")
@Html.DropDownList("Users", "-- Select A User --")
I am populating teams using the following code which works OK :
var teams = postroomEmplyees.GetPostRoomTeams();
ViewData["Teams"] = new SelectList(teams, "UID", "Name");
I want to delay loading of any data into ‘users’ until a value in ‘teams’ has been selected by the user… HOWEVER… if I load the page without binding anything to ‘users’ I understanbly get
'There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Blah'.'
In MVC can I have a dropdownlist load without binding to it.. and if so.. what the best way to achieve this ? Thanks!
I actually found a much more effiecent way.
I can set the type to empty and then when the page loads it does’t complain. IT stops me doing any unneeded fake loads on start.