Sometimes the data in a table is not ordered in a fashion you want and you can't change the database. Here is an easy way to order the items from within your controller:
ViewBag.cities= new SelectList(db.cities.Where(g => g.visible == true).OrderBy(g => g.name), "id", "name", myitem.cityId);
or
ViewBag.cities= new SelectList(db.cities.OrderBy(g => g.name), "id", "name");
Share This To :
0 comments:
Post a Comment