Error throws using ModelClientValidationRule in MVC 5?

心不动则不痛 提交于 2019-12-22 08:17:34

问题


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
 }

I get the following error :

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.

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>

回答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].



来源:https://stackoverflow.com/questions/29208111/error-throws-using-modelclientvalidationrule-in-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!