我在这里遵循了 ASP.Net 教程,效果很好:http ://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-与-the-entity-framework-in-an-asp-net-mvc-application
现在我自己尝试,它似乎不起作用。我一般是编程新手,所以请像我 7 岁一样跟我说话。谢谢!
控制器:
public ViewResult Index(string sortOrder)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name desc" : "";
var students = from s in db.ComputerMaintenanceModels
select s;
switch (sortOrder)
{
case "Name desc":
students = students.OrderByDescending(s => s.Name);
break;
}
return View(db.ComputerMaintenanceModels.ToList());
}
看法
@Html.ActionLink("Name", "Index", new { sortOrder=ViewBag.NameSortParm })
当我单击 Name 列时,它会处理,但 Order 不会改变。我错过了什么吗?我的代码正确吗?