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
if
statement, and/or is used in multiple places in your view.
- Everything that the function needs to determine it's logic already exists in the
Model
for 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…