gpt4 book ai didi

c# - 在 MVC 5 中使用 ModelClientValidationRule 会抛出错误?

转载 作者:行者123 更新时间:2023-11-30 12:58:32 28 4
gpt4 key购买 nike

我尝试在 MVC 5 项目中进行自定义客户端验证。当我添加以下代码时:

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
//Some Validation Here
}

我收到以下错误:

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 开始支持的网页版本

<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]

关于c# - 在 MVC 5 中使用 ModelClientValidationRule 会抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29208111/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com