【发布时间】:2011-06-03 08:51:40
【问题描述】:
我想做以下事情(我会分成两点):
在执行操作之前,如果视图模型在缓存中,则返回视图和视图模型而不执行操作。
如果不在缓存中,则继续执行动作,到达 OnActionExecuted 将视图模型放入缓存中。
如何在不执行操作(第一点)的情况下返回视图和视图模型?
这是代码。我的疑问用?????????表示:
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);
}
非常感谢。
最好的问候。
何塞。
【问题讨论】: