c# - Model validation based on the DataType -
i have project, classic 3 tier structure: datastore, businesslogic, web-frontend
in datastore have model (simplified) e.g. configmodel.cs:
public class configmodel { [datatype(datatype.emailaddress)] public string defaultsenderemail { get; set; } public ipaddress fallbackdns { get; set; } }
here comes question:
what's elegant way programmatically add validators according either actual datatype, or datatype attribute?
a few answers have considered myself far, did not find them satisfactory:
add [emailaddress] validation attribute parameter: don't want duplication , don't want reference mvc specific code in datastore layer.
make separate viewmodels , use automapper: since of models lot more complex that, i'd hate make specific viewmodels.
thanks!
i consider using automapper, not answer solution.
maybe can consider this: http://weblogs.asp.net/srkirkland/archive/2011/02/15/adding-client-validation-to-dataannotations-datatype-attribute.aspx
Comments
Post a Comment