Return View from ActionFilter

后端 未结 3 824
Happy的楠姐
Happy的楠姐 2020-12-16 11:37

I have an ActionFilter that checks if a parameter in the URL is valid. If it is not valid I have to render a View. I dont want to redirect, because I still need the ActionEx

相关标签:
3条回答
  • 2020-12-16 12:26

    Yes. Look at the source for HandleErrorAttribute.

    0 讨论(0)
  • 2020-12-16 12:29

    Try this

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

    And put the view you want rendered in to ~/Views/Shared/Error.ascx.

    0 讨论(0)
  • 2020-12-16 12:36

    HandleErrorAttribute had what I was looking for.

    filterContext.Result = new ViewResult
                {
                    ViewName = "MessagePage",
                    ViewData = filterContext.Controller.ViewData,
                    TempData = filterContext.Controller.TempData
                };
    
    0 讨论(0)
提交回复
热议问题