DataBinding a DropDownList in ASP.NET MVC 2
- by Daniel Coffman
I'm extremely frustrated trying to switch to MVC after a couple years of webforms development.
Here's my extremely simple problem that I can't manage to solve:
I have a list of States in a table called StateProvince.
I have a DropDownList.
I want the DropDownList to display all of the States in the StateProvince table and post the selected state back on HTTP PUT.
This is what I'm doing:
<%: Html.DropDownListFor(model = model.StateProvinceId, new SelectList(Model.StateProvinces, "StateProvinceId", "Name") )%
I'm getting an Object reference not set to an instance of an object. Why? How can I make this work?
Keep it simple, I know nothing about MVC.