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

前端 未结 3 973
野性不改
野性不改 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: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

提交回复
热议问题