I am an ASP.NET MVC developer and I am confused. What's the difference between Model, ViewModel and DTO (Data Transfer Object)? Is it ok for model to have methods that will save itself to database?
DTO is an object for passing data in case of communication between layers. It's a general pattern that is not tied to ASP.NET MVC.
ViewModel contains a data specific to particular view, is passed to that view in controller and is used in the view for rendering. It's a pattern specific to ASP.NET MVC (don't mix up with ViewModel from MVVM - they are different)
Model is a set of objects that represent your business domain. It can contain methods that will save it to DB depending of what pattern you will choose to build it (something like Active Record in your case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With