I am not sure this is an error in my code or maybe something else messing with it however I have a function were I am creating a simple list from a MVC model in an ActionResult
I have others that use OrderByDescending
and work but this is throwing an error for some reason.
[Authorize(Roles = "Administrator, Manager, User")]
[SessionExpire]
public ActionResult PrepareShipment(int id,string sortOrder)
{
//ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
//ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
Order orderResult = (from o in db.Orders.Include("OrderItems").Include("OrderItems.Item")
where o.OrderID == id
select o).First();
orderResult = orderResult.OrderByDescending(o => o.Item.ItemName);
return View(orderResult);
}
That is my complete ActionResult
the database has a table Order with another object called Item that object has a column called ItemName
. I already have a view with a list in it done exclusively in the view but now I have to order that data by the item name. This is so every time an action is done on the page the list stays in the same order as when it first loaded. Right now every time I reload the page the list reorders.