C# 用剃须刀打开错误的标签

C# 用剃须刀打开错误的标签,c#,html,asp.net-mvc,razor,C#,Html,Asp.net Mvc,Razor,我有两个选项卡,一个是“Compras”,另一个是“财政”,当我打开应用程序时,如果用户的角色是“68”,则应打开“财政”选项卡,否则打开“Compras”,问题是我打开“财政”选项卡时的当前操作方式正确,但它会打开“Compras”选项卡 我在这里检查用户的权限 ViewBag.isFiscal = false; if (Web.Security.CustomPrincipal.CurrentUser().IsAuthenticated)

我有两个选项卡,一个是“Compras”,另一个是“财政”,当我打开应用程序时,如果用户的角色是“68”,则应打开“财政”选项卡,否则打开“Compras”,问题是我打开“财政”选项卡时的当前操作方式正确,但它会打开“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>
  • @if(Model!=null&&Model.IdTemplate>0) { } 其他的 { }
但当我使用角色为68的用户打开时,它的打开方式如下:

标记为财政,但表格内容来自Compras表格,正确的财政是:

有人知道我遗漏了什么吗?

我找到了解决办法

我只在tab Compras中激活标记,现在我做了一个验证,将标记激活到Compras或Financial中

<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>
    }

@**@
@使用(Html.BeginForm(“Index”,“Home”,FormMethod.Post,new{@class=“form horizontal form compras”,id=“frmSaveCompras”,action=string.Format(“{0}/Home/Index”,pathRoot)}))
{
@Html.Partial(“_abacompa”,模型,视图数据)
}
@if(Model!=null&&Model.IdTemplate>0)
{
@使用(Html.BeginForm(“AbaContabil”,“Home”,FormMethod.Post,new{@class=“form horizontal form contabil”,id=“frmSaveContabil”,action=string.Format({0}/Home/AbaContabil”,pathRoot)}))
{
@Action(“AbaContabil”,“home”,新的{id=Model.IdItem,partial=(bool)ViewBag.partial,hash=(string)ViewBag.hash})
}
>
@Action(“abaescal”,“home”,新的{id=Model.IdItem,partial=(bool)ViewBag.partial,hash=(string)ViewBag.hash})
}
我找到了解决方案

我只在tab Compras中激活标记,现在我做了一个验证,将标记激活到Compras或Financial中

<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>
    }

@**@
@使用(Html.BeginForm(“Index”,“Home”,FormMethod.Post,new{@class=“form horizontal form compras”,id=“frmSaveCompras”,action=string.Format(“{0}/Home/Index”,pathRoot)}))
{
@Html.Partial(“_abacompa”,模型,视图数据)
}
@if(Model!=null&&Model.IdTemplate>0)
{
@使用(Html.BeginForm(“AbaContabil”,“Home”,FormMethod.Post,new{@class=“form horizontal form contabil”,id=“frmSaveContabil”,action=string.Format({0}/Home/AbaContabil”,pathRoot)}))
{
@Action(“AbaContabil”,“home”,新的{id=Model.IdItem,partial=(bool)ViewBag.partial,hash=(string)ViewBag.hash})
}
>
@Action(“abaescal”,“home”,新的{id=Model.IdItem,partial=(bool)ViewBag.partial,hash=(string)ViewBag.hash})
}