I consider a ViewModel itself, as a representation of a template for a view. I do not see as a problem the return of ViewModel
from a Action
or Web Service
, since the information being returned is what you intend with this method.
The problem in this case is whether one of the cases requires a lot of information (eg many properties for a detailed view of one entity) and one with a few (eg a listing in
grid
format) , and in such cases, it is preferable to perform the separation in different
ViewModel
's, especially when working with distributed information (Web Services, APIs) where traffic is important. If the intent of the method is the same for both cases, I do not see it as a problem since you save code.
ViewModel is not sent to the user in HTML format, this happens when your presentation layer renders HTML to the user. What is common is that in the body of APIs or Web Services requests, this ViewModel will be serialized according to what was requested in the Header Request (content-type), and this format may vary according to API support or Web service. The most common ones are: json
, xml
and soap
.