最近在搞的项目加载的时候出现了上述的问题,查了查,就发现原来是ASP.NET MVC 版本不兼容的问题,解决办法如下:
Upgrading an ASP.NET MVC 2 Project to ASP.NET MVC 3 Tools Update
ASP.NET MVC 3 can be installed side by side with ASP.NET MVC 2 on the same computer, which gives you flexibility in choosing when to upgrade an ASP.NET MVC 2 application to ASP.NET MVC 3. ASP.NET MVC 3可以与ASP.NET MVC 2同时安装在同一台电脑上,让你可以灵活地选择何时升级ASP.NET MVC 2应用程序到ASP.NET MVC 3版本。
To manually upgrade an existing ASP.NET MVC 2 application to version 3, do the following: 若要手动升级版本,执行以下操作
- Create a new empty ASP.NET MVC 3 project on your computer. This project will contain some files that are required for the upgrade. 在电脑上新建一个空的ASP.NET MVC 3项目。此项目包含一些升级所必须的文件。
- Copy the following files from the ASP.NET MVC 3 project into the corresponding location of your ASP.NET MVC 2 project. You'll need to update any references to thejQuery library to account for the new filename ( jQuery-1.5.1.js): 从 下面的ASP.NET MVC 3 项目中的文件复制到您的 ASP.NET MVC 2 项目的相应位置中。你需要更改所有对jQuery library的引用去适应新的文件名( jQuery-1.5.1.js)
- /Views/Web.config
- /packages.config
- /scripts/*.js
- /Content/themes/*.*
- Copy the packages folder in the root of the empty ASP.NET MVC 3 project solution into the root of your solution, which is in the directory where the solution’s .sln file is located. 复制空ASP.NET MVC 3项目的packages文件夹到你自己解决方案根目录里(.sln文件所在的目录)
- If your ASP.NET MVC 2 project contains any areas, copy the /Views/Web.config file to the Viewsfolder of each area. 如果你的ASP.NET MVC 2项目包含了其他区域,复制/Views/Web.config文件到所有区域的Views文件夹目录下
- In both Web.config files in the ASP.NET MVC 2 project, globally search and replace the ASP.NET MVC version. Find the following: 在 ASP.NET MVC 2 项目中的两个Web.config 文件内,在全局范围内搜索并替换的ASP.NET MVC 的版本号。找到以下内容:
System.Web.Mvc, Version=2.0.0.0
Replace it with the following: 作如下修改
System.Web.Mvc, Version=3.0.0.0
- In Solution Explorer, delete the reference to System.Web.Mvc (which points to the DLL from version 2), then add a reference to System.Web.Mvc (v3.0.0.0). 在解决方案资源管理器中删除(指向版本2的动态链接库的)对System.Web.Mvc的引用,然后添加一个对System.Web.Mvc(版本3)的引用
- Add a reference to System.Web.WebPages.dll and System.Web.Helpers.dll. These assemblies are located in the following folders: 添加对System.Web.WebPages.dll 和 System.Web.Helpers.dll的引用。这些程序集位于下面的文件夹:
- %ProgramFiles%\ Microsoft ASP.NET\ASP.NET MVC 3\Assemblies
- %ProgramFiles%\ Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies
- In Solution Explorer, right-click the project name and select Unload Project. Then right-click the project name again and select Edit ProjectName.csproj. 在解决方案资源管理器中右击项目名选择卸载项目,再右击一次并选择编辑 项目名.csproj 这个文件
- Locate the ProjectTypeGuids element and replace {F85E285D-A4E0-4152-9332-AB1D724D3325} with {E53F8FEA-EAE0-44A6-8774-FFD645390401}. 找到ProjectTypeGuids标记,并将{F85E285D-A4E0-4152-9332-AB1D724D3325} 替换成 {E53F8FEA-EAE0-44A6-8774-FFD645390401}
- Save the changes, right-click the project, and then select Reload Project. 保存修改,再次右击项目,然后选择重载项目
- In the application’s root Web.config file, add the following settings to the assemblies section. 在应用程序的根目录下的Web.config文件中添加以下设定到 assemblies section
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- If the project references any third-party libraries that are compiled using ASP.NET MVC 2, add the following highlighted bindingRedirect element to the Web.config file in the application root under the configuration section: 如果项目引用了任何在ASP.NET MVC 2框架下编译的第三方库,在上一步骤所述文件的configuration section下添加下面高亮的bindingRedirect 元素
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime>
Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4
ASP.NET MVC 4 can be installed side by side with ASP.NET MVC 3 on the same computer, which gives you flexibility in choosing when to upgrade an ASP.NET MVC 3 application to ASP.NET MVC 4.
The simplest way to upgrade is to create a new ASP.NET MVC 4 project and copy all the views, controllers, code, and content files from the existing MVC 3 project to the new project and then to update the assembly references in the new project to match any non-MVC template included assembiles you are using. If you have made changes to the Web.config file in the MVC 3 project, you must also merge those changes into the Web.config file in the MVC 4 project.
To manually upgrade an existing ASP.NET MVC 3 application to version 4, do the following:
- In all Web.config files in the project (there is one in the root of the project, one in the Views folder, and one in the Views folder for each area in your project), replace every instance of the following text (note: System.Web.WebPages, Version=1.0.0.0 is not found in projects created with Visual Studio 2012):
System.Web.Mvc, Version=3.0.0.0 System.Web.WebPages, Version=1.0.0.0 System.Web.Helpers, Version=1.0.0.0 System.Web.WebPages.Razor, Version=1.0.0.0
with the following corresponding text:
System.Web.Mvc, Version=4.0.0.0 System.Web.WebPages, Version=2.0.0.0 System.Web.Helpers, Version=2.0.0.0 System.Web.WebPages.Razor, Version=2.0.0.0
- In the root Web.config file, update the webPages:Version element to "2.0.0.0" and add a newPreserveLoginUrl key that has the value "true":
<appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="PreserveLoginUrl" value="true" /> </appSettings>
- In Solution Explorer, right-click on the References and select Manage NuGet Packages. In the left pane, select Online\NuGet official package source, then update the following:
- ASP.NET MVC 4
- (Optional) jQuery, jQuery Validation and jQuery UI
- (Optional) Entity Framework
- (Optonal) Modernizr
- In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
- Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
- Save the changes, close the project (.csproj) file you were editing, right-click the project, and then select Reload Project.
- If the project references any third-party libraries that are compiled using previous versions of ASP.NET MVC, open the root Web.config file and add the following three bindingRedirect elements under the configuration section:
<configuration> <!--... elements deleted for clarity ...--> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>