Emulating Nested Master Pages in ASP.NET MVC
I'm trying to create the following scenario in ASP.NET MVC; I have a MasterPage for the global site UI, then I need to create some pages which are based on that masterpage but all need to have some additional UI (same UI should be shared between them), where as other pages also use the same MasterPage but don't need to share that UI with the former pages.
How can this 开发者_如何学Gobe creates using ASP.NET MVC? Some example would be much appreciated.
Thanks!
You create both main master page and nested master page.
And in controller actions when you return a view, you can set the master page for the view depending on your needs.
return View("yourviewname", "yourmasterpage", yourdata);
If you don't want to set the master pages on every action like the above call, you can write a class that implements IResultFilter and assign master/nested master pages dynamically in OnResultExcecuting override.
var viewResult = fitlerContext as ViewResult;
viewResult.Master = "yourMaster"
精彩评论