2

Assuming I write a custom attribute...

public class SpecialActionFilterAttribute : System.Web.Mvc.ActionFilterAttribute
{
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
    }
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        // set some parameters here. 
    }
    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
    }
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
    }
}

And then I create a custom ViewEngine, and override FindView/FindPartialView...

    public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {
        // how can I get those parameters here? 

        return base.FindView(controllerContext, viewName, masterName, useCache);
    }

I'd like to be able to utilize the Custom Attribute to pass 'flags' of sorts to the custom view engine. is this at all possible?

1 Answer 1

5
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
    var controller = controllerContext.Controller;

    var controllerType = controller.GetType();

    //now we can use reflection
    var attributes = controllerType.GetAttributes();

    // how can I get those parameters here? 

    return base.FindView(controllerContext, viewName, masterName, useCache);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.