I have a project with a classic 3-level structure: DataStore, BusinessLogic, Web-Frontend
In the DataStore, I have a model (simplified), for example. ConfigModel.cs:
public class ConfigModel { [DataType(DataType.EmailAddress)] public string DefaultSenderEmail { get; set; } public IPAddress FallbackDNS { get; set; } }
The question arises:
What an elegant way to programmatically add Validators according to the actual DataType type or DataType attribute?
A few answers that I still considered myself, but did not find them satisfactory:
Add the verification attribute [EmailAddress] to the parameter: I do not want duplication, and I do not want to reference the special MVC code at my DataStore level.
Create separate ViewModels and use AutoMapper: since some of my models are much more complex, I would not want to create specific ViewModels.
Thanks!
source share