Shorten this if statement in Razor to one line

前端 未结 4 899
情书的邮戳
情书的邮戳 2021-02-18 13:08

Can i shorten this to one line? I have tried various ways but can\'t quite get it right.

@if(SiteMap.CurrentNode.Title == \"Contact\")
{
    @:
4条回答
  •  花落未央
    2021-02-18 13:54

    The shortest possible way to do is like:

    @(SiteMap.CurrentNode.Title == "Contact" ? "
    " : "")

    or

    @(SiteMap.CurrentNode.Title == "Contact" ? @"
    " : "")

    or even shorter if you don't repeat your html code

提交回复
热议问题