使用 IF/ELSE 在 Razor 中显示和标签

我有一些标签:


    <div class="page-tabs">

    <ul class="nav nav-tabs">

        <li class='@(ViewBag.IsAmendment == "0" ? "active" : "")'>

            <a href='@Url.Action("ReviewDetails", "SongsManagement")' title="Original">Original</a>

        </li>

        @if (!Model.OriginalWork.IsNew)

    {

        <li class='@(ViewBag.IsAmendment == "1" ? "active" : "")'>

            <a href='@Url.Action("ReviewDetails", "SongsManagement",new {isAmendment=1} )' title="Amendment">Active Amendment</a>

        </li>

}

    </ul>

</div>

当前显示的是 Original,然后如果 DB 中的 IsNew 发生更改,则显示 Active。有没有办法可以隐藏原始选项卡。然后在有有效修订时将其与原件一起展示?


慕丝7291255
浏览 177回答 1
1回答

catspeake

<div class="page-tabs">&nbsp; &nbsp; <ul class="nav nav-tabs">&nbsp; &nbsp; @if (!Model.OriginalWork.IsNew)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if(ViewBag.IsAmendment == "1")&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href='@Url.Action("ReviewDetails", "SongsManagement")' title="Original">Original</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; <li class='@(ViewBag.IsAmendment == "1" ? "active" : "")'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href='@Url.Action("ReviewDetails", "SongsManagement",new {isAmendment=1} )' title="Amendment">Active Amendment</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; }&nbsp; &nbsp; </ul></div>
打开App,查看更多内容
随时随地看视频慕课网APP