views:

50

answers:

1

Hey guys

I got a problem with a custom ViewEngine. I try to overrite the FindView method to set the master view without having to define it in each and every view page.

public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
    if (string.IsNullOrEmpty(masterName))
    {
        masterName = this.MasterView;
    }
    return base.FindView(controllerContext, viewName, masterName, useCache);
}

From the debuggers view everything looks fine: I don't set the property MasterPageFile on the view page, masterName comes in as an empty string, masterName gets set to this.MasterView (which gets set by initializing the view engine).

Trouble is: The browser displays "Content controls are allowed only in content page that references a master page." without the debugger showing up.

Does anyone know why or if this is even an expected behaviour?

Thanks in advance!

+1  A: 

Ok, I've solved it. To get it to work (at least in my case) one just has to remove the default view engine:

ViewEngines.Engines.Clear();

And then add the new (custom) one:

ViewEngines.Engines.Add(new AreaViewEngine(this.MasterView));

et voila, it works.

Dänu
Yes, that's how I do it too.
bzlm
Yeah... maybe there's a way to change the priorities of viewengines or something like that, so that no clear would be necessary... who knows ;-)
Dänu