I have the following code in a Controller:
newclass.Brands = db.Brands.OrderByDescending(x => x.Brand1 != "Not classified").ThenBy(x => x.Brand1);
When I create a SelectList using this in the View:
@Html.DropDownList("Brand_id", new SelectList(Model.Brands, "Brand_id", "Brand1"), new {@class="dropdown_edit"})
It works perfectly - it places the list of brands in alphabetical order and the 'Not classified' option at the bottom of the list.
However, when I have this is the Controller:
newclass.Brands = db.Brands;
And this in the View:
@Html.DropDownList("Brand_id", new SelectList(Model.Brands.OrderByDescending(x => x.Brand1 != "Not classified").ThenBy(x => x.Brand1), "Brand_id", "Brand1"), new {@class="dropdown_edit"})
The DropDownList always defaults to the instruction in the ThenBy statement, it's as if the first OrderBy is overwritten by the ThenBy - which shouldn't be the case?
What am I missing?
EDIT: I'm using EF and the newclass is a Viewmodel derived from the EF class Brands. The class definition is:
public class Class1
{
public IEnumerable<Brand> Brands { get; set; }
}