There is some data I would like to retrieve from the model and display on the master page. Right now, I am using the hack of having the master page access the model directly but that doesn't seem to fit with the seperation of layers design methodology of
MVC.
So besides making a procedure that gets called with every controller action, how would I go about making a universal bit of code that runs with the controllers to retrieve the data from the model.
create a base class for your controllers which extends System.Web.Mvc.Controller
override the RednerView(ViewContext) method and add your data to viewContext.ViewData.
If you're using strongly typed viewdata then you'll probably what to write a base class for all your view data types which contains the data for your master page.
However, there's a bug with the way the ViewMasterPage<T> works regarding the type of the generic parameter.
Michael Jenk...
Member
20 Points
7 Posts
MVC - Creating code that runs with every controller action.
Dec 24, 2007 06:13 AM|LINK
There is some data I would like to retrieve from the model and display on the master page. Right now, I am using the hack of having the master page access the model directly but that doesn't seem to fit with the seperation of layers design methodology of MVC.
So besides making a procedure that gets called with every controller action, how would I go about making a universal bit of code that runs with the controllers to retrieve the data from the model.
Thanks in advance. :)
ASP.NET Futures .net 3.5 MVC
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: MVC - Creating code that runs with every controller action.
Dec 24, 2007 03:05 PM|LINK
create a base class for your controllers which extends System.Web.Mvc.Controller
override the RednerView(ViewContext) method and add your data to viewContext.ViewData.
If you're using strongly typed viewdata then you'll probably what to write a base class for all your view data types which contains the data for your master page.
However, there's a bug with the way the ViewMasterPage<T> works regarding the type of the generic parameter.
Check out the following post for a nice solution http://forums.asp.net/t/1195178.aspx