Say I have a class that wraps the Controller class:
public class MyController : Controller
{
public string SomeProperty {get;set;}
public override void OnActionExecuting(...)
{
SomeProperty = "hello";
}
}
Now in my site.master, I want to have access to the SomeProperty that I just set.
How can I do this?
In each view
<%= ViewContext.Controller %>will give you the instance of the controller that rendered this view. If you have a base controller for all actions and the property is on this base controller you could cast and access the property. Writing a helper method to do this might be even better:with the following helper defined: