I'm working with MVC4.
I have this following dropdownlist/selectlist:
@Html.DropDownList("EmployerID", String.Empty)
ViewBag.EmployerID = new SelectList(db.Employers, "EmployerID", "Name", contact.EmployerID);
and I want this dropdownlist/selectlist to be sorted by the "Name". What should I do?
Many thanks! :)
Add OrderBy
to your db.Employers
@Html.DropDownList("EmployerID", String.Empty)
ViewBag.EmployerID = new SelectList(db.Employers.OrderBy(x => x.Name),
"EmployerID", "Name", contact.EmployerID);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With