asp.net-mvc – 在操作过滤器上使用缓存数据,以避免再次执行操作
发布时间:2020-12-16 07:09:45 所属栏目:asp.Net 来源:网络整理
导读:我想做以下(我将分为两点): 在执行操作之前,如果viewmodel位于缓存中,则返回视图和viewmodel而不执行操作. 如果不在缓存中,则继续执行操作,并到达OnActionExecuted以将viewmodel放入缓存中. 如何在不执行操作的情况下返回视图和视图模型(第一点)? 这是代码
我想做以下(我将分为两点):
>在执行操作之前,如果viewmodel位于缓存中,则返回视图和viewmodel而不执行操作. 如何在不执行操作的情况下返回视图和视图模型(第一点)? 这是代码.我怀疑用???????表示: public override void OnActionExecuting(ActionExecutingContext filterContext) { //IF the viewmodel exists dont execute the action again if (filterContext.HttpContext.Cache["viewmodel"]!=null) { filterContext.Result=??????? } base.OnActionExecuting(filterContext); } public override void OnActionExecuted(ActionExecutedContext filterContext) { //Cast de model ContentDetailVM model = (ContentDetailVM)filterContext.Controller.ViewData.Model; filterContext.HttpContext.Cache.Insert("viewmodel",model); //we're asking for a close section if (model.CurrentSection.HideAccess == true) { //pass to the client some flag in order to show the div filterContext.Controller.ViewData["showoverlaylayer"]=true; } base.OnActionExecuted(filterContext); } 非常感谢提前. 最好的祝福. 何塞. 解决方法public override void OnActionExecuting(ActionExecutingContext filterContext) { var model = filterContext.HttpContext.Cache["viewmodel"]; if (model != null) { var result = new ViewResult(); result.ViewData.Model = model; filterContext.Result = result; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 从ASP.NET 3.5应用程序在IFRAME中运行GWT应用程序(包括Appl
- iis – 是否需要serviceAutoStartProvider属性来自动启动AS
- asp.net-mvc – 如何将锚/哈希的参数添加到RedirectToRoute
- asp.net – 无法使用URL告知服务器显式查看json文件,告知Fi
- asp.net-mvc – 当可观察数组为空时如何显示无数据?
- asp.net-mvc – 我应该把我的控制器业务逻辑放在MVC3中
- 二、Asp.Net Core WebAPI——OcelotDemo
- asp.net – 在vb.net Webapi项目中缺少request.CreateRespo
- 使用Asp.net在jquery中更改事件
- MSTest与Ninject,MVC3和WCF
推荐文章
站长推荐
热点阅读