随着 ASP.NET MVC 4 的发布,不少用户的开发环境中同时存在 ASP.NET MVC 3 和 ASP.NET MVC 4 ,但是安装 ASP.NET MVC 4 之后再运行 ASP.NET MVC 3 版本的程序时会出现以下类型的错误
错误 1 类型“System.Web.Mvc.ModelClientValidationRule”同时存在于“c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll”和“c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll”中 D:\Projects\Visual Studio 2010\MvcWijmoApplication1\MvcWijmoApplication1\Models\AccountModels.cs 242 28 MvcWijmoApplication1
原因是 ASP.NET MVC 3 应用程序是使用的 RTM 版本,如果需要同时使用 3 和 4 两个版本,需要修改应用程序的配置。操作步骤如下:
1、在 web.config 中添加以下配置信息
1: <appSettings>
2: <add key="webpages:Version" value="1.0.0.0"/>
3: <add key="ClientValidationEnabled" value="true"/>
4: <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
5: </appSettings>
2、修改工程文件 Projectname.csproj
找到以下配置信息
1: <Reference Include="System.Web.WebPages"/>
2: <Reference Include="System.Web.Helpers" />
将以上配置修改为
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
重现加载工程,并重新编译工程。
更多 ASP.NET MVC 4.0 发布说明请访问:ASP.NET MVC 4