In ASP.NET MVC3 how do you stay DRY with very similar but slightly different viewmodels? -
In ASP.NET MVC3 how do you stay DRY with very similar but slightly different viewmodels? -
in building app, created generic object model store values, viewmodel looks bit @ moment:
public class fooviewmodel { public int id { get; set; } public byte footype { get; set; } [required] [display(name = "bar name")] public string name { get; set; } [required] public string email { get; set; } //etc, etc }
the problem is: depending on footype, want have display name different , email not required type 1 , 2, required type 3 , 4.
we tried seperating out properties differ per type in classes inherit one, validation a fallback on specified in base of operations type, didn't work.
currently, alternative seems to create viewmodel each footype (and seperate controllers , view), leads lot of code duplication.
what other ways maintain dry?
to benefit validation context (e.g. validating objects in different contexts), recommend using fluentvalidation library.
asp.net-mvc-3 viewmodel
Comments
Post a Comment