Problem using Razor after migrating MVC 2.0 to MVC

2019-04-10 11:33发布

问题:

I migrated a MVC 2.0 site to MVC 3.0, using that : Migrating MVC 2.0 -> 3.0

Using ASPX as View Engine works great now...

But I tried to create a Razor view and got that error:

The view 'TestView' or its master was not found. The following locations were searched:

    ~/TestView.aspx
    ~/TestView.ascx
    ~/Views/Color/TestView.aspx
    ~/Views/Color/TestView.ascx
    ~/Views/Shared/TestView.aspx
    ~/Views/Shared/TestView.ascx

How can I enable razor on that?

I´m using Visual Studio 2010... Creating a brand new MVC 3 Web Application enables Razor fine!

Thanks

回答1:

Try adding ViewEngines.Engines.Add(new RazorViewEngine()); to your global.asax file



回答2:

Please review

In Solution Explorer, delete the reference to System.Web.Mvc (which points to the version 2 DLL). Then add a reference to System.Web.Mvc (v3.0.0.0). Also add a reference to System.WebPages.dll and System.Web.Helpers.dll.