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

北城余情 提交于 2019-11-29 23:50:29

问题


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


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/630833/how-to-use-dynamic-master-page-in-asp-net-mvc-rc-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!