3

I upgraded an MVC 2 project to MVC 3. How can I set the default view engine to Razor on an existing project?

Edit: Sorry, I was rather unclear. I want to have Razor be the default type in the Add View dialog.

Matthew Nichols
  • 4,866
  • 4
  • 41
  • 48
  • possible duplicate of [Can we use Razor on an existing Asp.Net 4 WebSite?](http://stackoverflow.com/questions/3253869/can-we-use-razor-on-an-existing-asp-net-4-website) – jgauffin Feb 25 '11 at 14:22

3 Answers3

9

Short answer:

Change in global.asax to use both webforms and razor:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ViewEngines.Engines.Add(new WebFormViewEngine());
jgauffin
  • 99,844
  • 45
  • 235
  • 372
3

The Add View dialog should default to a Razor selection in the view engine combobox if your project has at least one Razor file already or if it has no Aspx files (i.e. a project with no view files at all). Are you not seeing that behavior?

marcind
  • 52,944
  • 13
  • 125
  • 111
  • 1
    We upgraded a web forms project to MVC 3 and for some reason the add view dialog always defaults to ASPX even though all we have in there are Razor views and no ASPX views. In my instance this behavior is not working as expected. – CatDadCode Feb 08 '12 at 16:23
1

There is a MVC3 Upgrade tool.

You can find the tool and the tutorial here: http://blogs.msdn.com/b/marcinon/archive/2011/01/13/mvc-3-project-upgrade-tool.aspx

When you create a new view you can choose the viewengine but i don't know possibilities to set razor like default.

Gio
  • 17
  • 3