Error “The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>”

你说的曾经没有我的故事 提交于 2019-11-27 21:21:10

You might unintentionally have two versions of the MVC framework loaded into the same application. To confirm, download MVC 2 Futures from http://aspnet.codeplex.com/releases/view/41742. There is a file MvcDiagnostics.aspx in this ZIP file.

  1. Copy MvcDiagnostics.aspx to the root of your web project.
  2. Reproduce the error.
  3. After reproducing the error, go to /MvcDiagnostics.aspx and see if it complains (will be in bold red lettering) about multiple versions of the framework being loaded. The tool should suggest a resolution if this is the case.

Don't forget to delete MvcDiagnostics.aspx from your project when you are done.

I was getting this error upgrading my MVC 1.0 project to MVC 2.0. If you are doing this have a look at http://weblogs.asp.net/leftslipper/archive/2010/03/10/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2-rtm.aspx

Double check your web.config against a new MVC 2.0 project.

Bohemian

Doing either a batch->build->clean at the solution level OR a clean at the project level usually takes care of this if you have already done the due diligence of removing/replacing the undesired version(s) of System.Web.Mvc from project references and *.config files...

You could try using the ASP.NET MVC 3 Application Upgrader

Best to do this with your code under source control, that way you can eye-ball everything that is changes. It updates your javascript which I didn't want so I reverted that, and only kept the changes it makes to the web.config for razor.

Be sure to read about what it does and what it doesn't support on this blog post.

I solved this problem for myself by having my custom view engine inherit RazorViewEngine directly.

public class MainViewEngine : RazorViewEngine
{
    public MainViewEngine()
    {...
}}

And then registering that viewengine in the Global.asax file Application_Start event:

ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new MainViewEngine());

Clearly this assumes that you are using Razor.

Check the reference to System.Web.Mvc.dll file in your reference. Make sure its pointing to C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll

If its pointing to the one under ASP.NET MVC 4 directory then open your project file in a notepad. Look for

<Reference Include="System.Web.Mvc">
  <Private>False</Private>
</Reference>

This should be changed to

<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35, processorArchitecture=MSIL" />

This will help to point to the specific MVC version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!