MVC - Creating code that runs with every controller action.http://forums.asp.net/t/1197639.aspx/1?MVC+Creating+code+that+runs+with+every+controller+action+Mon, 24 Dec 2007 15:05:31 -050011976392075079http://forums.asp.net/p/1197639/2075079.aspx/1?MVC+Creating+code+that+runs+with+every+controller+action+MVC - Creating code that runs with every controller action. <p>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.</p> <p>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.</p> <p>&nbsp;Thanks in advance. :)</p> 2007-12-24T06:13:05-05:002075601http://forums.asp.net/p/1197639/2075601.aspx/1?Re+MVC+Creating+code+that+runs+with+every+controller+action+Re: MVC - Creating code that runs with every controller action. <p>create a base class for your controllers which extends System.Web.Mvc.Controller</p> <p>override the RednerView(ViewContext) method and add your data to viewContext.ViewData.</p> <p>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.</p> <p><b>However,</b> there's a bug with the way the ViewMasterPage&lt;T&gt; works regarding the type of the generic parameter.<br> </p> <p>Check out the following post for a nice solution <a href="/t/1195178.aspx">http://forums.asp.net/t/1195178.aspx</a>&nbsp;</p> 2007-12-24T15:05:31-05:00