tags:

views:

92

answers:

2

In an attribute inheriting from ActionFilterAttribute is there a way I can get to the current master page name OnActionExecuting?

Thanks, Nath

+1  A: 

This is not possible, because at this point it is not clear which view you will return. That also means you can not know which Masterpage you will render.

What you want to achieve by this?

Malcolm Frexner
Different ViewData for the masterpage, depending on which one it is.
DeletedAccount
+1  A: 

I think it is impossible (there is no ActionResult at that time) but you could try in OnActionExecuted(). This should work:

public override void OnActionExecuted(ActionExecutedContext filterContext)
{
    var masterName = (filterContext.Result as ViewResult).MasterName;
}
eu-ge-ne
I'm trying to populate ViewData based on which masterpage we're using. I think OnActionExecuted is too late?
DeletedAccount
OnActionExecuted() code is executed just before View code. You can populate ViewData there and it will be accessible in your View.
eu-ge-ne