我是 ASP.NET MVC4 的新手,我有一个搜索/过滤器表单,您可以在其中过滤多个参数
所以这是我的控制器
public ActionResult Index(string page, int? neighborhoodID, int? accommodationType) {
...
}
我刚在想。我正在使用 Model 类为我的登录/注册使用数据注释和验证。
有没有办法可以使用 Model 类过滤值?
现在我只查看请求的参数并在我的 linq 查询中使用它们来获取过滤后的记录。
我是 ASP.NET MVC4 的新手,我有一个搜索/过滤器表单,您可以在其中过滤多个参数
所以这是我的控制器
public ActionResult Index(string page, int? neighborhoodID, int? accommodationType) {
...
}
我刚在想。我正在使用 Model 类为我的登录/注册使用数据注释和验证。
有没有办法可以使用 Model 类过滤值?
现在我只查看请求的参数并在我的 linq 查询中使用它们来获取过滤后的记录。
我认为你应该创建一个IndexViewModel类
public class IndexViewModel
{
public int? NeighbourhoodId { get; set; }
public int? AccomodationType { get; set; }
}
然后添加@model IndexViewModel到您的视图顶部
似乎来自下拉列表,因此将 viewModel 属性映射到这些下拉neigbourhoodId列表accomodationType
然后控制器方法将是这样的:
public ActionResult Index(string page, IndexViewModel model)
{
// You can use model.NeighbourhoodId and model.AccomodationType the same way you did with parameters
}