我无法弄清楚如何在详细信息页面中执行排序。我有一个包含订单列表的经典页面,每行我都有一个actionlink来返回该订单的详细信息视图。 我试试这个
public ActionResult Details(int? anno,int? nr, string centro, string sortOrder)
{
ViewBag.Codice = String.IsNullOrEmpty(sortOrder) ? "Articolo_desc" : "";
if (anno == null && nr == null && string.IsNullOrEmpty(centro))
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
else
{
string s = "anno=" + Request.QueryString["anno"] + "&nr=" + Request.QueryString["nr"] + "¢ro=" + Request.QueryString["centro"];
ViewBag.search = s.Replace("search=", "").Replace("%3D", "=");
}
var righe = from d in db.DETAILS
where d.Anno == anno && d.Num == nr && d.Centro == centro
select new DetailsOrdersView
{
Articolo = r.Codice,
...
};
if (righe == null)
return HttpNotFound();
switch(sortOrder)
{
case "Articolo_desc":
righe = righe.OrderByDescending(i => i.Articolo);
break;
default:
righe = righe.OrderBy(i => i.Articolo);
break;
}
return View(righe);
}
}
并在详细视图中
@Html.ActionLink("codice","Details", new { sortOrder = ViewBag.Codice, ViewBag.search })
但我在排序时得到了错误的请求,这就是路线 订单/详细中将sortOrder = Articolo_desc&安培;搜索=阿鲁%3D2017%26nr%3D6%26centro%3D1
答案 0 :(得分:0)
@Html.ActionLink("codice", "Details", new { sortOrder = ViewBag.Codice, anno = ViewBag.Anno, centro = ViewBag.Centro , nr= ViewBag.Numero })
我解决了上面