用剃刀打开错误的标签

时间:2016-12-11 13:14:41

标签: c# html asp.net-mvc razor

我有两个标签,一个是“Compras”和其他“Fiscal”,当我打开应用程序时,如果用户有角色“68”应该打开标签财政,否则打开“​​Compras”,问题是当我打开选项卡时我正在做的当前方式Fiscal选择正确,但它会打开选​​项卡Compras。

我在这里查看用户的许可。

ViewBag.isFiscal = false;
                    if (Web.Security.CustomPrincipal.CurrentUser().IsAuthenticated)
                    {
                        if (Web.Security.CustomPrincipal.CurrentUser().IsInRole("68"))
                        {
                            ViewBag.isFiscal = true;
                        }
                    }

在这里,我尝试打开财政标签:

<ul class="nav nav-tabs">

        <li class="@(ViewBag.isFiscal == false ? "active" : "" )">
                <a data-toggle="tab" href="#compras" data-etapa="78">Compras</a>
            </li>

    <li class="@(ViewBag.isFiscal == true ? "active" : "" )">
            @if (Model != null && Model.IdTemplate > 0)
            {
                <a data-toggle="tab" href="#fiscal" data-etapa="80">Fiscal</a>
            }
            else
            {
                <a href="javascript:void(0);">Fiscal</a>
            }
        </li>
</ul>

但是当我打开一个有角色68的用户时,它会像这样打开: enter image description here

它标记为Fiscal,但表单的内容来自Compras表单,正确的Fiscal是这样的: enter image description here

有人知道我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

我只是在标签Compras中激活标签,现在我进行验证以将标签激活在Compras或财务中

<div id="compras"class="tab-pane @( (bool)Session["isFiscal"] == false ? "active" : "" )">
        @*<div id="compras" class="tab-pane active">*@
            @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "form-horizontal form-compras", id = "frmSaveCompras", action = string.Format("{0}/home/index", pathRoot) }))
            {
                @Html.Partial("_abaCompra", Model, ViewData)
            }
        </div>
    @if (Model != null && Model.IdTemplate > 0)
    {
        <div id="contabil" class="tab-pane">
            @using (Html.BeginForm("AbaContabil", "Home", FormMethod.Post, new { @class = "form-horizontal form-contabil", id = "frmSaveContabil", action = string.Format("{0}/home/AbaContabil", pathRoot) }))
            {
                @Html.Action("AbaContabil", "home", new { id = Model.IdItem, partial = (bool)ViewBag.partial, hash = (string)ViewBag.hash })
            }
        </div>

        <div id="fiscal"  class="tab-pane @((bool)Session["isFiscal"] == true ? "active" : "" )">>
            @Html.Action("AbaFiscal", "home", new { id = Model.IdItem, partial = (bool)ViewBag.partial, hash = (string)ViewBag.hash })
        </div>
    }