本文介绍了ASP.NET的MVC OnResultExecuting修改filterContext结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的问题。我该如何去重写在我的控制器的OnResultExecuting方法并强制进行不同的ActionResult呢?
样code如下。目前,原ActionResutl继续执行和我的新RedirectResult被忽略。
RedirectResult redirectResult =新RedirectResult(http://www.google.com);
filterContext.Result = redirectResult;
base.OnResultExecuting(filterContext);
解决方案
这将如果忽略OnActionExecuted方法是可行的。
示例:
保护覆盖无效OnActionExecuted(ActionExecutedContext filterContext)
{
filterContext.Result =新RedirectResult(http://google.com);
base.OnActionExecuted(filterContext);
}
Simple question. How do I go about overriding the OnResultExecuting method in my Controller and force a different ActionResult instead?
Sample code is below. Currently the original ActionResutl continues to execute and my new RedirectResult is ignored.
RedirectResult redirectResult = new RedirectResult("http://www.google.com");
filterContext.Result = redirectResult;
base.OnResultExecuting(filterContext);
解决方案
It would be possible if you override the OnActionExecuted method.
Example:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
filterContext.Result = new RedirectResult("http://google.com");
base.OnActionExecuted(filterContext);
}
这篇关于ASP.NET的MVC OnResultExecuting修改filterContext结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!