-1

Online I saw someone say "When working with a view, create a view model. This view model you will bind to your view. Never bind domain objects to your view."

Is this good practice, to "never bind domain objects to your view"? What's the thinking behind this?

Thanks!

WebDevGuy2
  • 1,159
  • 1
  • 19
  • 40
  • 1
    See [this post and all the answers/discussions](http://stackoverflow.com/q/821276/304683). – EdSF Feb 25 '17 at 20:20

1 Answers1

1

we use view model when our domain object is different from view e.g

i have two models

Student

Subjects

and i want a single view to display table of Students and table of Subjects so what will i do ? i will use view model like

class viewmodeltest
 {
   public list<Student> students {get;set;}
   public list<Subjects> subjects {get;set;}

 }

and yes its best practice to use view model because all UI validation logic is done on the view models with data annotations

Usman
  • 4,615
  • 2
  • 17
  • 33