Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assigning ViewData to nested masterpages

Is there a good way to assign ViewData to nested master pages? For example, in my top level masterpage I might have info on the logged in user. I also have a nested masterpage that is displayed when the user is on any departmental page. I want that data available ONLY on departmental pages.

So this is how it looks:

Top Level Master Page - Includes ViewData["userData"]
    |
    |
    ---> Nested Master Page - Includes ViewData["departmentalData"]

So whenever I have a view that uses the nested master page it would include both ViewData["userData"] and ViewData["departmentalData"]. But if I am only using the top level master page then I only have ViewData["userData"]. Is this possible?

like image 858
codette Avatar asked May 06 '09 20:05

codette


1 Answers

If you insist on using ViewData as the data-carrier to the master pages (instead of using Html.RenderAction(...) from the MvcContrib project which I probably would use) then if you can identify in which cases the nested masterpage will be used, you can setup an ActionFilter to input the needed data into ViewData["departmentalData"].

like image 68
AndreasKnudsen Avatar answered Sep 28 '22 02:09

AndreasKnudsen