将 Razor 中的 if 语句缩短为一行 [英] Shorten this if statement in Razor to one line
本文介绍了将 Razor 中的 if 语句缩短为一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将其缩短为一行吗?我尝试了各种方法,但不能完全正确.
@if(SiteMap.CurrentNode.Title == "联系方式"){@:<div class="contact">}
解决方案
可能有更简单的解决方案,但这应该有效:
@Html.Raw((SiteMap.CurrentNode.Title == "Contact") ? "" : "")Can i shorten this to one line? I have tried various ways but can't quite get it right.
@if(SiteMap.CurrentNode.Title == "Contact")
{
@:<div class="contact">
}
解决方案 There might be an even simpler solution but this should work:
@Html.Raw((SiteMap.CurrentNode.Title == "Contact") ? "<div class='contact'>" : "")
这篇关于将 Razor 中的 if 语句缩短为一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文