In Razor, there\'s a curious rule about only allowing closed HTML within an if block.
if
See:
Razor doesn't understand unclosed ht
Declare razor helper using @helper HeplerName(), call by @HeplerName() anywhere. And you can add params if you want.
@helper HeplerName()
@HeplerName()
@if (condition) { @MyContent() } else { @MyContent() } @helper MyContent() { }