ASP.NET MVC data annotate domain model in the web project -


i've seen somewhere how before on blog forgot or how. lets have domain in class library. i'd data annotate properties of domain viewmodel in web project.

how accomplish this?

for example. domain in class library:

public class person {    public int id {get; set;}    public string firstname {get; set;} } 

in web project, there this:

//do need set attribute here? public class createpersonviewmodel{     [required()]    [displayname("first name")]    public string firstname {get; set;} } 

this code can mapped person without tool. partial or something.

the whole idea of using view model decouple domain model , have adapted needs of view. view model should declared in web project , contain necessary properties , formatting attributes particular view might require. domain model shouldn't polluted view specific data annotations. if model looks this:

public class person {    public int id { get; set; }    public string firstname { get; set; } } 

you have following view model:

public class createpersonviewmodel {    [required]    [displayname("first name")]    public string firstname { get; set; } } 

and have controller fetch model repository, map view model (automapper can here) , pass view model view.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -