Alphabetically Ordering a SelectList in MVC
You could use the OrderBy
extension method:
<%: Html.DropDownListFor(
x => x.ModelId,
new SelectList(Model.VehicleModels.OrderBy(x => x.Name), "Id", "Name"),
"-- Select a model --"
) %>
thanks to Darin I was able to come up with the slightly modified solution of his which instead lead to me resolving this in the VM like so
List<Reason> reasonList = _db.Reasons.OrderBy(m=>m.Description).ToList();
ReasonList = new SelectList(reasonList, "Id", "Description");
In case where you have an editor template for your dropdownlist, this will sort it based on text.
selectList.OrderBy(x => x.Text)