If using “helpers” you refer to things like HtmlHelper , then no, they are not used by the controller, since theoretically you can use your controllers and reuse them with a completely different rendering mechanism (for example, WPF), because the controller does not respond for rendering.
If you say, it seems to me, helper classes / methods that manipulate your data, ready to be placed in the model using the controller, and then passed to the presentation for presentation, then you can consider the “business logic” layer . For example, if you were talking about a (typical) example of a bank account, you could:
public class BankAccountService { public IEnumerable<string> GetAllAccountIdsForCustomer(int customerId) {
Then your controller:
public ActionResult AccountNumbers(int customerId) { var model = new AccountNumbersModel(); model.CustomerId = customerId; model.AccountNumbers = BankAccountService.GetAllAccountIdsForCustomer(customerId); return View(model); }
Obviously, in this example, you will need to define a class called AccountNumbersModel , and you probably also want to consider using Dependency Injection to provide an instance of BankAccountService for your controller, but describing how to do everything that is beyond the scope of this answer .
The advantages of this approach give you testability and separation , each part of the code is responsible for one task, and you reduce the complexity of each individual part and make it easier to make changes without breaking anything.
source share