views:

42

answers:

1

Is there a way to change the root folder for the views to the bin/views folder?

+1  A: 

You can subtype WebFormsViewEngine:

public class MyViewEngine : WebFormViewEngine
{
    public MyViewEngine() {
        MasterLocationFormats = new[] {
            "~/bin/Views/{1}/{0}.master",
            "~/bin/Views/Shared/{0}.master"
        };

        ViewLocationFormats = new[] {
            "~/bin/Views/{1}/{0}.aspx",
            "~/bin/Views/{1}/{0}.ascx",
            "~/bin/Views/Shared/{0}.aspx",
            "~/bin/Views/Shared/{0}.ascx"
        };

        PartialViewLocationFormats = ViewLocationFormats;
    }
}

Then edit Global.asax to use it:

    private void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
        // replace default WebForms view engine.
        ViewEngines.Engines.Remove(ViewEngines.Engines.OfType<WebFormViewEngine>().Single());
        ViewEngines.Engines.Add(new Namespace.MyViewEngine());
    }
Craig Stuntz
Looks easy enough. Thanks :)
borisCallens