I\'m developing an ASP.NET MVC 5 application, with C# and .NET Framework 4.6.1.
I have this View
:
@model MyProject.Web.API.Models.Aggreg
I leave this in case it helps someone else. I had a very similar problem and none of the answers helped.
We had in a view this line at the top:
IEnumerable exitFromTrustDeed = (ViewData["ExitFromTrustDeed"] as IEnumerable).Select(e => new SelectListItem() {
Value = e,
Text = e,
Selected = Model.ExitFromTrustDeed == e
});
and then below in the view:
@Html.DropDownListFor(m => m.ExitFromTrustDeed, exitFromTrustDeed, new { @class = "form-control" })
We had a property in my ViewData with the same name as the selector for the lambda expression and for some reason that makes the dropdown to be rendered without any option selected.
We changed the name in ViewData to ViewData["ExitFromTrustDeed2"]
and that made it work as expected.
Weird though.