我有两个用于筛选的链接:
@Html.ActionLink("Customer 1", "Index", new { customer = 1 })
@Html.ActionLink("Project A", "Index", new { project = "A" })
带过滤器的控制器:
public ViewResult Index(int? customer, int? project) {
var query = ...
if (customer != null) {
query = query.Where(o => o.CustomerID == customer);
}
if (project != null) {
query = query.Where(o => o.ProjectID == project);
}
return View(query.ToList());
}
我现在可以按客户或项目进行过滤,但不能同时按两个过滤!如果我点击客户1,则url = Object?customer=1。如果我点击项目A,则url = Object?project=a。我想先点击客户1,然后再点击项目A,得到url = Object?customer=1&project=a。这可行吗?还是我应该用另一种方式实现?谢谢!