tags:

views:

120

answers:

2

Hi, I want to put some common information in my MasterPage to be shown on all pages such as Categories. How can I do that instead of filling that area in my each action.

+1  A: 

You could derive all controllers from a single base controller and add all data that is the same across all controllers and all actions to the view data there, and render this in your master page.

Data that is specific to a single action gets added to the view data in the derived controller.

There is an example in the ASP.NET MVC Tutorial here: http://www.asp.net/learn/mvc/tutorial-13-cs.aspx

David Tischler
I've made an abstract class but I did not think of adding this to the constructor. Nice solution!
yapiskan
No, not the constructor. How about a filter attribute?
Matt Hinze
What do you mean by filter attribute? I have searched for filter attribute in google but I cannot find any resource. Could you please explain a little more?
yapiskan
Hmm, do you mean, make a filter attribute for view methods which will fill the Categories of the ViewModel?
yapiskan
A: 

Look at the RenderAction helper method in the Futures DLL available at www.codeplex.com/aspnet. This allows you to render a partial view (aka usercontrol) that gets it ViewData from a different controller.

Matthew