I have a MVC 5 application using a lot of the standard features. I have a number of dropdownlists across the app that render properly, except for one.
In the Controller:
ViewBag.TitleLookup = new SelectList(db.TitleLookups, "Title", "Title", person.Title);
return View(person);
In the View:
@Html.DropDownList("Title",(SelectList)ViewBag.TitleLookup,string.Empty)
@Html.DropDownList("TitleLookup", string.Empty)
Both dropdown lists render the options properly, however, the first does not have the properly selected item. The second has the wrong Name so would not be submitted to the server on a post, however it did have the "valid" property indicating the validation was active.
I have stepped through the controller and the SelectListItems are getting built correctly along with the selected property on the proper Item getting set to True.
So to ask a concrete question: Why does the first dropdownlist not render the proper selected item? Is there indeed something crazy about having the property called "Title"?
I can change the datamodel if I absolutely have to, but feels like it should be able to work without doing that.