How to set default value to select list in MVC during run time

Unfortunately @Html.DropDownListFor() behaves a little differently than other helpers when rendering controls in a loop. This has been previously reported as an issue on CodePlex (not sure if its a bug or just a limitation) Create a custom EditorTemplate for the type in the collection. In /Views/Shared/EditorTemplates/provider_service_dtls.cshtml (note the name must match the name of … Read more

What is the best ways to bind @Html.DropDownListFor in ASP.NET MVC5?

The strongly typed view model approach which does not use dynamic stuff like ViewBag You can add a new property to your view model for the SELECT options of type IEnumrable<SelectListItem>. view model is a simple POCO class used to transfer data between view to action method and vice versa. They are specific to the … Read more

There is no ViewData item of type ‘IEnumerable’ that has the key ‘xxx’

Ok, so the answer was derived from some other posts about this problem and it is: If your ViewData contains a SelectList with the same name as your DropDownList i.e. “submarket_0”, the Html helper will automatically populate your DropDownList with that data if you don’t specify the 2nd parameter which in this case is the … Read more