Reputation: 25312
What really should be a part of action? Currently my actions are pretty simple, they consist of some service call and returning View (in simplest case):
public ActionResult SomeAction(int id)
{
var myViewModel = _someViewService.Get(id);
return View(myViewModel);
}
At the same time my colleague feels free to put code directly in the action (and I am not comforable with this).
So what is the right way?
Upvotes: 0
Views: 23
Reputation: 2755
Conceptually the controller (and its action methods) should have only the code necessary to obtain the data which will be used by the view, generally, the view model.
It will vary on the size of your application, quantity of tiers and complexity. So it may contain only a simple call as your code sample, or, in other cases, it may contain a lot of lines handling the viewmodel before use it in a view.
The most important point here is avoid access data services and other data provider directly from view.
Upvotes: 3