Обратный просмотр от ActionFilter

У меня есть 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);
    }

Ответы

Ответ 1

HandleErrorAttribute имел то, что я искал.

filterContext.Result = new ViewResult
            {
                ViewName = "MessagePage",
                ViewData = filterContext.Controller.ViewData,
                TempData = filterContext.Controller.TempData
            };

Ответ 2

Да. Посмотрите на источник для HandleErrorAttribute.

Ответ 3

Попробуйте это

[HandleError]
public ActionResult MyAction (int id)
{
    // ...
}

И поместите представление, которое вы хотите отобразить, в ~/Views/Shared/Error.ascx.