首页 新闻 会员 周边 捐助

.net mvc OutputCache疑问

0
悬赏园豆:15 [已关闭问题] 关闭于 2016-03-01 13:17

使用OutputCache进行页面 缓存,但是遇到一个问题,

Action中缓存15秒,对于请求参数Name和Gender区分缓存

 [OutputCache(Duration = 15, VaryByParam = "Name,Gender")]
        public ActionResult Index(Employee e)
        {
            var employees = new[]{
                new Employee(){ID=1,Name="ares",Gender="Male"},
                new Employee(){ID=2,Name="bres",Gender="Male"},
                new Employee(){ID=3,Name="btres",Gender="Male"},
                new Employee(){ID=4,Name="arest",Gender="Male"},
                new Employee(){ID=5,Name="cte",Gender="FMale"},
                new Employee(){ID=6,Name="ctD",Gender="FMale"},
                   new Employee(){ID=3,Name="bUtres",Gender="FMale"}
            };
            List<Employee> lst = employees.ToList();
            if (e != null)
            {
                if (!string.IsNullOrEmpty(e.Name))
                    lst = lst.FindAll(r => r.Name.Contains(e.Name));
                if (!string.IsNullOrEmpty(e.Gender))
                    lst = lst.FindAll(r => r.Gender == e.Gender);
            }
            return View(new EmployeeSearchResultA { SearchPara = e, SearchResult = lst });
        }

如图:请求http://localhost:11265/OutputCache?Name=&Gender=Male

 

下拉框中选择FMale,

点击查询,提交http://localhost:11265/OutputCache?Name=&Gender=FMale
按理来说这时候Gender参数值变了,应该重新请求,但是并不是预想的结果:

而是如图:

请求地址没有错误,但是页面结果却是之前请求Male时的结果,不知道这是啥原因?

哪位大神能够解惑?

摆脱菜鸟的主页 摆脱菜鸟 | 初学一级 | 园豆:16
提问于:2016-03-01 11:47
< >
分享
所有回答(1)
0

[OutputCache(Duration = 15, VaryByParam = "Name,Gender")]

这里写错了,应该是,使用分号分隔多个参数

[OutputCache(Duration = 15, VaryByParam = "Name;Gender")]

摆脱菜鸟 | 园豆:16 (初学一级) | 2016-03-01 13:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册