Razor syntax - how to conditionally wrap some inner HTML

前端 未结 4 1904
滥情空心
滥情空心 2021-02-02 12:42

In Razor, there\'s a curious rule about only allowing closed HTML within an if block.

See:

Razor doesn't understand unclosed ht

4条回答
  •  花落未央
    2021-02-02 12:46

    Declare razor helper using @helper HeplerName(), call by @HeplerName() anywhere. And you can add params if you want.

    @if (condition)
    {
      
    @MyContent()
    } else { @MyContent() } @helper MyContent() { }

提交回复
热议问题