在MVC 5中使用ModelClientValidationRule引发错误? [英] Error throws using ModelClientValidationRule in MVC 5?
问题描述
我尝试在MVC 5 Project中进行自定义客户端验证.当我添加以下代码时:
I try to do the custom client side validation in MVC 5 Project. When I add the following code:
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
//Some Validation Here
}
我收到以下错误:
找不到类型名称'ModelClientValidationRule'.此类型已转发到程序集'System.Web.WebPages,版本= 2.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'.考虑添加对该程序集的引用.
The type name 'ModelClientValidationRule' could not be found. This type has been forwarded to assembly 'System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.
但是当我检查web.config
文件时,我使用的是从0.0开始支持的WebPages版本
But when I check the web.config
file, I am using WebPages version supported from 0.0
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
推荐答案
我的System.Web.Mvc
被删除,当我重新添加它时,它开始给我您提到的此错误.原因是,早先我使用的是System.Web.Mvc [3.0.0.1]
,它被删除,而在添加时,我添加了System.Web.Mvc [4.0.0.1]
.因此,为解决此问题,我删除了System.Web.Mvc [4.0.0.1]
并添加了System.Web.Mvc [3.0.0.1]
.
My System.Web.Mvc
got deleted and when I added it back, it started giving me this error that you have mentioned. The reason for it was that, earlier I was using System.Web.Mvc [3.0.0.1]
, which got deleted and while adding back, I added System.Web.Mvc [4.0.0.1]
. So, to fix this issue, I deleted System.Web.Mvc [4.0.0.1]
and added System.Web.Mvc [3.0.0.1]
.
这篇关于在MVC 5中使用ModelClientValidationRule引发错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!