How to use dynamic master page in ASP.NET MVC RC 1.0

前端 未结 3 975
野性不改
野性不改 2021-01-03 16:18

I don\'t know how to using dynamic master page in ASP.NET MVC RC 1.0. Please help!

相关标签:
3条回答
  • 2021-01-03 16:45

    You can specify the name of the master page when using the View() helper method:

    return View("About", "AlternateMaster", model);
    

    AlternateMaster would resolve to ~/Views/Shared/AlternateMaster.master

    Found this here

    0 讨论(0)
  • 2021-01-03 16:54

    I got this to work by creating a base controller that handled the OnActionExecuted event. In the OnActionExecutedevent I assign the master page. Then I made all my other controllers inherit from the base class.

    public class BaseController : Controller
    {
         protected override void OnActionExecuted(ActionExecutedContext filterContext) {
             var action = filterContext.Result as ViewResult;
             if (action != null) {
                 action.MasterName = MyApp.Properties.Settings.Default.Theme;
             }  
    
             base.OnActionExecuted(filterContext);
         }
    }
    

    I wrote a post about this if you want more detail

    0 讨论(0)
  • 2021-01-03 16:55

    There's a reasonably maintainable solution discussed on http://forums.asp.net/p/1394235/2991293.aspx where you create a common site master descendant and use that for all your own views. There's also a CodeProject entry that looks interesting that uses a custom ViewEngine at http://www.codeproject.com/KB/aspnet/ASPNETMVCDynamicThemes.aspx.

    I need to do this too, but I haven't tried either solution yet so I don't have a feel yet for which is better overall. IMO, dynamic skinning is a crucial feature for MVC, particularly to cater to user personalization.

    0 讨论(0)
提交回复
热议问题