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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -