How to Transfer DataAnnotation metadata to ViewModel with AutoMapper with Betty's Approach

大兔子大兔子 提交于 2019-12-04 08:54:02

The metadata provider isn't used by Automapper, it uses Automapper.

You don't need to call it directly, it's automatically called by MVC as long as you register it with MVC on startup in Global.asax.cs, for example:

ModelMetadataProviders.Current = new MetadataProvider(
        AutoMapper.Mapper.Engine.ConfigurationProvider);

ModelValidatorProviders.Providers.Add(new ValidatorProvider(
        AutoMapper.Mapper.Engine.ConfigurationProvider);

or:

ModelMetadataProviders.Current = new MetadataProvider(
        (AutoMapper.IConfigurationProvider)AutoMapper.Mapper.Configuration);

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