views:

48

answers:

1

hi,

Im developing a custom view engine for implementing themes for my asp.net mvc 2 web app. The problem that I am facing is that in this function:

public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)

The parameter "masterName" is always empty, although the viewName is not empty and that view has a master page associated to it.

I would like to know the master page, so I can have a default theme and allow to create a theme that only changes the masterpages but not the content pages. So when a theme is selected, I want to use the masterpage of the theme but the content page of the default theme. But also I want to give the ability to create themes that override the master page and some content pages, and some other not. For this I would only need the masterName that the page is using, but I receive an empty string :(

Do you have any ideas?

Thanks in advance! Juan

A: 

The parameter "masterName" is optional. By default a view will use the master page defined in the View, but if the paraeter is specified it will override this with the mast page supplied.

eg:

Return View("viewname", Model); // uses default master page
Return View("viewname", Model, "MasterName"); // users supplied MasterName

Therefore one solution is to leave the master name value blank, unless overriden by a selected theme, and only then to override it in the View call. This doesn't need a custom view engine

Clicktricity
As I want to change also some pages depending on the them I need a custom view engine. Is there any way that I can get the masterpage name that is defined in the View?
Juan
Its not something that is made available, unless you dig very deep into the WebFormViewEngine within the Render methods. Unless it's overridden its not generally needed.
Clicktricity