Asp.net

兩個 dll 中都存在“ModelClientValidationRule”類型

  • December 11, 2013

我下載了用asp.net mvc3 Visual Studio 2010編寫的範例原始碼

通過Visual Studio 2012打開解決方案文件。它將原始碼轉換為 2012 並打開解決方案。

當我建構解決方案時出現錯誤:

錯誤 1 類型“System.Web.Mvc.ModelClientValidationRule”存在於“c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll”和“c”中:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll’ C:\studyCode\MVCDemo-Part12\MVCDemo-Part12\MVCDemo\Attributes\驗證\EqualAttribute.cs 54 28 MVCDemo

只需從解決方案參考中刪除System.Web.WebPages

這個答案也可以解決您的問題:

  1. 在根 Web.config 文件中,使用鍵 webPages:Version 和值 1.0.0.0 添加一個新條目。
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>

2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.

3.Locate the following assembly references:

   <Reference Include="System.Web.WebPages"/>
   <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 "/>

4.保存更改,關閉您正在編輯的項目 (.csproj) 文件,然後右鍵點擊該項目並選擇重新載入。

參考:http ://forums.asp.net/t/1723108.aspx/1

也可以試試:http ://www.asp.net/learn/whitepapers/mvc4-release-notes#_Toc303253815

或者你也可以試試這個

編輯:

ProjectName.csproj

改變

<Reference Include="System.Web.WebPages"/> 

<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/><br/><br/>

注意:此問題的可能重複項

引用自:https://stackoverflow.com/questions/14710099