下面是我的search应用程序的MVC模型。
public class SearchFilters
{
public SearchFilters()
{
MinPrice = "10000";
MaxPrice = "8000000";
}
public IEnumerable<SelectListItem> Categories { get; set; }
public string[] CategoriesId { get; set; }
public IEnumerable<SelectListItem> Locations { get; set; }
public string[] LocationID { get; set; }
public IEnumerable<SelectListItem> Status { get; set; }
public string[] StatusID { get; set; }
public string MinPrice { get; set; }
public string MaxPrice { get; set; }
}现在,当用户搜索任何记录时,它将通过model数据传递选定的params,我的get请求如下所示:
[HttpGet]
public ActionResult Search([Bind(Prefix = "searchModel")]SearchFilters smodel)
{
CategoryViewModel model = new CategoryViewModel();
model = _prepareModel.PrepareCategoryModel("Search", smodel);
if (model.projects.Count == 0)
{
return Json(new { message = "Sorry! No result matching your search", count = model.projects.Count }, JsonRequestBehavior.AllowGet);
}
return PartialView("_CategoryView", model);
}如果传递的参数是string或int,我可以设置VaryByParam = "param",或者如果多个参数设置为';'分隔的值。但是我如何在这里缓存复杂的model参数呢?
发布于 2016-03-18 18:32:45
根据MSDN值,VaryByParam值应该是
一个分号分隔的字符串列表,对应于GET方法的查询字符串值或POST方法的参数值。
因此,对于复杂的模型,您需要指定它的所有属性,用分号分隔。您还需要考虑到您拥有的绑定前缀。因为您的HttpGet请求很可能如下所示:
http://../someUrl?searchModel.MinPrice=1&searchModel.MaxPrice=5&searchModel.CategoriesId=10&searchModel.LocationID=3&searchModel.StatusID=8VaryByParam值应该是:
VaryByParam="searchModel.MinPrice;searchModel.MaxPrice; searchModel.CategoriesId;searchModel.LocationID;searchModel.StatusID"https://stackoverflow.com/questions/36091494
复制相似问题