我想将数据注释属性和 IClientValidatable
接口(interface)放在两个单独的程序集中,以实现关注点分离。一个称为 Common,另一个称为 Comman.Web。
这些链接解释了它在 MVC 5 中的工作原理:
Keeping IClientValidatable outside the model layer
http://www.eidias.com/blog/2012/5/25/mvc-custom-validator-with-client-side-validation
不幸的是,在 MVC 6 中没有
DataAnnotationsModelValidatorProvider.RegisterAdapter(
typeof(MyValidationAttribute),
typeof(MyValidationAttributeAdapter)
);
它在 ASP.net core MVC 6 中如何工作?我用的是RC1。
最佳答案
在 Startup.cs
中的 ConfigureServices
方法中:
services.AddMvc(options =>
{
options.ModelValidatorProviders.Insert(0, new CustomModelValidatorProvider());
});
随着 ASP.NET Core 1.0 API 的更改,您必须调整代码。您可以在 asp.net 存储库中找到示例实现:DataAnnotationsModelValidatorProvider.cs
关于data-annotations - ASP.net core MVC 6 数据注释关注点分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36692627/