I am using Visual Studio 2013 and creating MVC application and I have bind dropdownlist like this:
var list = context.Roles.OrderBy(r => r.Name).ToList()
.Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name })
.ToList();
ViewBag.Roles = list;
and in CSHTML:
@Html.DropDownList("Role", (IEnumerable<SelectListItem>)ViewBag.Roles, "Select ...")
Now I want set selected value in Edit time!
What should I do to select that coming id or name in dropdownlist please help me to do this?
Thanks in advance.