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
2009-01-20 08:18:48
I've made an abstract class but I did not think of adding this to the constructor. Nice solution!
yapiskan
2009-01-20 08:28:43
No, not the constructor. How about a filter attribute?
Matt Hinze
2009-01-20 13:38:45
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
2009-01-21 07:26:09
Hmm, do you mean, make a filter attribute for view methods which will fill the Categories of the ViewModel?
yapiskan
2009-01-21 07:29:13
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
2009-01-21 02:09:19