使用IF / ELSE在Razor中显示和选项卡

时间:2018-08-03 11:22:24

标签: c# asp.net-mvc 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>

当前显示的是“原始”,然后,如果在数据库中更改了“ IsNew”,则会显示“活动”。有什么办法可以隐藏“原始”选项卡。然后在有有效修正案时将其与原件一并显示?

1 个答案:

答案 0 :(得分:0)

<div class="page-tabs">
    <ul class="nav nav-tabs">
    @if (!Model.OriginalWork.IsNew)
    {
        if(ViewBag.IsAmendment == "1")
        {
            <li>
                <a href='@Url.Action("ReviewDetails", "SongsManagement")' title="Original">Original</a>
            </li>
        }
        <li class='@(ViewBag.IsAmendment == "1" ? "active" : "")'>
            <a href='@Url.Action("ReviewDetails", "SongsManagement",new {isAmendment=1} )' title="Amendment">Active Amendment</a>
        </li>
    }
    </ul>
</div>