How to set state of dropdownlist
for default value to the one stored in database in edit view when using auto generated models via edmx (not created manually).
Here is my code :
View :
@Html.DropDownListFor(model => model.site_id, new SelectList(ViewBag.site_id, "id", "name"), "Select Any", new {@class="form-control",required="required",autofocus="autofocus" })
Controller :
ViewBag.site_id = dbContext.axi_sites;
Been looking for the solution for quite a while, none match to the exact requirement.
C# code:
In View:
Html Output:
Why should we bother. We can use jquery too.
add jquery 1.10.3 in your code. and code below in your page where you want dropdownlistfor selected value
write in View part