问题描述
我在查看页面上出现错误,因此尽管我正在开发mvc3,但我将我的visual studio更新为mvc4.我第一次使用NuGet进行了更新,但无法正常工作,我通过独立的MVC4进行了更新.这样就行了.但是,当我尝试运行MVC3项目时,出现以下错误:
I got error on my view page so I updated my visual studio to mvc4, though I am working on mvc3. I 1st updated using NuGet but it don't works so, I updated through standalone MVC4. so it worked. But when I tried to run MVC3 project it gives me following Error:
有人可以帮我吗?
推荐答案
在Views文件夹中的web.config文件中,位于system.web.webPages.razor下的host元素
Inside the web.config file in the Views folder there is the host element under system.web.webPages.razor
对于MVC3项目,它应该如下所示:
This should be as follows for an MVC3 project:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
对于MVC4,它是:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
对于MVC3,您还需要检查pages元素
You also need to check the pages element is as follows for MVC3
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
和sectionGroup元素:
and the sectionGroup element:
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
在项目根目录下的主web.config文件中,需要确保Assemblys元素如下:
In the main web.config in the root directory of the project you need to make sure that the assemblies element is as follows:
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
还有更多要做的更改-最好的选择是查看MVC3项目和MVC4项目的web.config文件,并删除不应该存在的内容.
There are more changes to make - best bet is to look at the web.config files for an MVC3 project and an MVC4 project and remove the stuff that shouldn't be there in yours.
这篇关于编译错误:“版本高于参考程序集"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!