Search code examples
asp.net-mvcrazorviewengine

How to default your asp.net-mvc site to look for razor views first?


I am converting all of my views over to razor so I have created all new view files but I haven't deleted the aspx file (I just have them excluded from the project). When i go to test my site, it seems to try to look for and load the aspx files. When I delete these files, it works fine and defaults to my razor cshtml files.

My issues, I that i want to keep my aspx files around for a little bit (at least until i know everything is working).

Is there anyway to have an asp.net-mvc site look for razor view files first so i don't need to delete my aspx files to get this to work?


Solution

  • The default order for view engines is Web Forms then Razor. Just change the order.

    protected void Application_Start() {
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new RazorViewEngine()); ViewEngines.Engines.Add(new WebFormViewEngine()); // remaaining calls here // ... }