我在某些数据过滤方面有一些问题;我希望,从下面的下拉菜单中,能够通过批准或不批准来显示项目列表。
当用户创建一个新项目时,其中一个字段被“批准”,这是一个布尔值。该复选框未选中,当项目有Go时,用户会选择该复选框作为已批准的项目。
基本上,当用户选择“已批准”选项时,我希望重定向到已经批准的项目列表。
我怎么能这么做?
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Project Execution <span class="caret"></span></a>
<ul class="dropdown-menu">
<li> @Html.ActionLink("Approved", "Index", "NEWPROJECTs")</li>
<li role="separator" class="divider"></li>
<li>@Html.ActionLink("On Going", "Index", "NEWPROJECTs")</li>
<li role="separator" class="divider"></li>
<li>@Html.ActionLink("List", "Index", "PROJECTEXECUTIONs")</li>
</ul>
发布于 2017-05-12 16:35:51
使用路由参数的
如果您有一个控制器操作来处理这些操作中的一个或多个操作,那么您可能需要提供一个路由值来确定您应该通过哪些数据进行过滤:
public ActionResult NewProjects(string filter)
{
// Check the filter that was used and filter the content that you
// will pass to the view accordingly
// Get your projects prior to filtering
var projects = _context.Projects;
switch (filter)
{
case "ONGOING":
projects = projects.Where(p => p.Status == "ONGOING");
break;
default:
projects = projects.Where(p => p.Status == "APPROVED");
break;
}
return View(projects);
}然后,在构建操作链接时,只需将filter指定为路由值,以便控制器操作可以使用它并正确地筛选数据:
<li>
@Html.ActionLink("Approved", "Index", "NEWPROJECTs", new { filter = "APPROVED"})
</li>
<li role="separator" class="divider"></li>
<li>
@Html.ActionLink("On Going", "Index", "NEWPROJECTs", new { filter = "ONGOING"})
</li>https://stackoverflow.com/questions/43942393
复制相似问题