-
Notifications
You must be signed in to change notification settings - Fork 0
23 DropDownList Options
M. Fares edited this page Apr 6, 2018
·
1 revision
- To order the items in a dropdown list
In the action, order the list according to the name/value.
public ActionResult Create()
{
ViewBag.DepartmentId = new SelectList(db.Departments.OrderBy(n => n.Name), "Id", "Name");
return View();
}- To replace a white space element in the dropdown list when the property is nullable or add an item to the dropdown list
@Html.EnumDropDownListFor(model => model.Level, "Select Faculty Level", htmlAttributes: new { @class = "form-control" })
@Html.DropDownList("DepartmentId", null, "Select Department", htmlAttributes: new { @class = "form-control" })