The @functions block lets you define utility functions directly in the view, rather than adding them as extensions to the @Html helper or letting the controller know about display properties. You’d want to use it when you can meet these conditions:
- The functionality is tied closely to the view and is not generally useful elsewhere (such as “How wide do I make my columns”).
- The functionality is more than a simple
ifstatement, and/or is used in multiple places in your view. - Everything that the function needs to determine it’s logic already exists in the
Modelfor the view.
If you fail the first one, add it as a @Html helper.
If you fail the second one, just inline it.
If you fail the third one, you should do the calculation in your controller and pass the result as part of the model.