I've been using the MVCScaffolding feature to create a CRUD UI for my data stored using EF4.1
It works well for basic scenarios and binds all the data to text boxes.
However, I want the "Title" property of my "Person" object to bind to a select list. I was hoping not to have to create a View Model but rather stick with the view binding to the actual Person Model.
public class Person {
public string Title { get; set; }
.......
This is in my view but the selected item doesn't bind correctly. It always shows "Mr" as the selected item even though the actual data might be different.
@Html.DropDownListFor(model => model.Title, new SelectList(new[] { "Mr", "Mrs", "Ms", "Miss", "Sir", "Dr", }, Model.Title))
This doesnt work either:
@Html.DropDownList("Title", new SelectList(new[] { "Mr", "Mrs", "Ms", "Miss", "Sir", "Dr", }, Model.Title))
However, this does:
@Html.DropDownList("TitleX", new SelectList(new[] { "Mr", "Mrs", "Ms", "Miss", "Sir", "Dr", }, Model.Title))
But I get an "Object reference not set to an instance of an object." exception when trying to update the record.
How, can I get this to work with minimum disruption to my model or controller?