我有一个ActionFilter来检查URL中的参数是否有效.如果它无效,我必须渲染一个视图.我不想重定向,因为我仍然需要ActionExecutingContext.可以这样做吗?
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Guid processIdentifier = (Guid)filterContext.RouteData.Values["processIdentifier"];
//if processIdentifier not found render a view with message and some other objects in ViewData
filterContext.Controller.ViewData.ModelState.AddModelError("WrongProcessIdentifier", "The process-id you supplied is not valid");
base.OnActionExecuting(filterContext);
}
Run Code Online (Sandbox Code Playgroud)
Mat*_*s F 39
HandleErrorAttribute 得到了我想要的东西.
filterContext.Result = new ViewResult
{
ViewName = "MessagePage",
ViewData = filterContext.Controller.ViewData,
TempData = filterContext.Controller.TempData
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8983 次 |
| 最近记录: |