Isn't the idea of MVC separate function and mapping? What if you want to reuse the same list with different orders?
I would have thought it would be better since it only sorts if for the specified control.
Add the property to the model you use for the view:
public SelectList Fruit { get; set; }
Fill this list in your constructor (I use Entity Framework):
model.Fruit= new SelectList(db.tblFruit.Select(f => new { Id = f.ID, Name = f.Name }), "ID", "Name", "[Select Fruit]");
Then add your selection list:
@Html.DropDownListFor(x => x.ID, new SelectList(Model.Fruit.OrderBy(y => y.Text), "Value", "Text"), "-- Select One --", new { @class = "form-control" })
source share