ASP.net核心MVC 6数据注释分离问题 [英] ASP.net core MVC 6 Data Annotations separation of concerns
问题描述
我想将数据注释属性和IClientValidatable
接口放在两个单独的程序集中,以实现关注点的分离.一个叫做Common,另一个叫做Comman.Web.
I want put the Data Annotations Attribute and the IClientValidatable
interface in two seperate assemblies to have separation of concerns. One is called Common and the other Comman.Web.
这些链接说明了它在MVC 5中的工作方式:
These links explain how it works in MVC 5:
http://www.eidias.com/blog/2012/5/25/mvc-custom-validator-with-client-side-validation
不幸的是,在MVC 6中没有
Unfortunately in MVC 6 there is no
DataAnnotationsModelValidatorProvider.RegisterAdapter(
typeof(MyValidationAttribute),
typeof(MyValidationAttributeAdapter)
);
它如何在ASP.net核心MVC 6中工作?我使用RC1.
How does it work in ASP.net core MVC 6? I use the RC1.
推荐答案
在Startup.cs
中,在ConfigureServices
方法中:
services.AddMvc(options =>
{
options.ModelValidatorProviders.Insert(0, new CustomModelValidatorProvider());
});
随着ASP.NET Core 1.0 API的更改,您必须调整代码.您可以在asp.net存储库中找到一个示例实现: DataAnnotationsModelValidatorProvider.cs
You have to adjust your code as the ASP.NET Core 1.0 API is changed. You could find a sample implementation in the asp.net repo: DataAnnotationsModelValidatorProvider.cs
这篇关于ASP.net核心MVC 6数据注释分离问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!