I have a requirement to change the master page used based on the current culture. I can do this fairly easily by overring View, OnResultExecuting or OnActionExecuting and this works fine for the majority of my pages.
My prob开发者_StackOverflow中文版lem is that I have several views that do not use master pages and I obviously do not want to set the master page for these views. I am having trouble finding out in code if a view has a master page - masterName is null or emtpty string in all cases.
Any ideas?
Try this...
public ActionResult Home()
{
MyModel model = new MyModel{MasterPage="SomeMaster"};
returnView(model);
}
<%@ Page Title="" Language="C#" MasterPageFile="/Views/Shared/<%= model.MasterPage %>" Inherits="System.Web.Mvc.ViewPage" %>
This way if you don't have a master page defined it will not change it :)
精彩评论