A @helper in Razor ultimately defines a function you can invoke from anywhere inside the view. The function can output literal text and can contain code blocks and code expressions.
Don’t forget that heavy amounts of code in a view can lead to grief.
You have @PluralPick(Model.Count, "child", "children"). @helper PluralPick(int amount, string singular, string plural) { <span> @amount @(amount == 1 ? singular : plural) </span> } OUTPUT FOR 4: You have 4 children. OUTPUT FOR 1: You have 1 child.