我有这个actionlink,允许用户支持索引视图。
@Html.ActionLink("Opened Date", "Index", new {sortOrder= ViewBag.OpenedDateParm, currentFilter=ViewBag.CurrentFilter})
这是在控制器中处理的地方
ViewBag.OpenedDateParm = sortOrder == "Date" ? "OpenedDate desc" : "Date";
如果当前排序是desc,我想排序asc,反之亦然。我是否使用?:来评估动作链接中的条件?
答案 0 :(得分:2)
在控制器操作中执行此操作。如果当前值为asc
,则会将ViewBag.OpenedDateParm设置为desc
,反之亦然
ViewBag.OpenedDateParm = sortOrder == "asc" ? "desc" : "asc";
在您的视图中,
@Html.ActionLink("Opened Date", "Index","YourControllerName",
new { sortOrder = ViewBag.OpenedDateParm,
currentFilter = ViewBag.CurrentFilter },null)