Reputation: 1322
Wouldn't it be better to have a method in the viewmodel that returns the model?
I think it's more organized that way because the viewmodel takes responsibility of how it's going to be mapped. But maybe there are a bunch of good reasons not to do it that way.
EDIT: I think my question, more than asking for automapper specifically, is to compare the approach of mapping the values in the controller as opposed to having the viewmodel return the model.
Upvotes: 3
Views: 309
Reputation: 574
It is not recommended to use Automapper at all. You have your own choice and there are many alternatives to Automapper too such as OTIS and ObjectCastor. You can also write your own binding in a delegate or function and reuse that too.
Automapper however I personally find is quite lightweight and works with generics specially beautiful if you are using IOC or dependency injection, not just for view models.
Upvotes: 3
Reputation: 1039080
It is not recommended to use AutoMapper to map the values between the domain model and the view model. You could do this mapping manually if you want but you are taking the risk to get bored pretty quickly. You could also use any mapping technique that you feel confortable with. Personally I like and use AutoMapper because I find it pretty easy.
The important thing is to have controller actions that always pass/take view models to/from views.
Upvotes: 4