隐藏基于当前视图MVC 5的_LoginPartial.cshtml中的注册和登录链接

时间:2016-03-27 20:09:40

标签: asp.net-mvc asp.net-mvc-partialview

我想在新用户注册时隐藏注册和登录链接。这是视图说"注册几乎完成,请检查您的电子邮件并确认电子邮件地址"。

以下是" else语句"对于未经授权的用如果我可以确定插入了View _LoginPartial,我可以隐藏注册用户的链接。

目前:

else
{
    <ul class="nav navbar-nav navbar-right" style="background-color:darkblue;">
        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: new { @returnUrl = "/StoreMaster/Stores/PickLocation" }, htmlAttributes: new { id = "registerLink", style = "color:white;" })</li>


        <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: new { @returnUrl ="/StoreMaster/Stores/PickLocation"}, htmlAttributes: new { id = "loginLink", style = "color:white;" })</li>
    </ul>
}

我想说: &#34;如果View == thisViewName,则隐藏这些链接&#34;

1 个答案:

答案 0 :(得分:2)

您可以在视图中获取名称,然后在如下所示的条件下使用它:

@{
    var  pageName = ViewContext.RouteData.Values["Action"].ToString();
}

@if (pageName != "DisplayEmail")
{
    <div class="navbar-collapse collapse" style="background-color:darkblue;">

    <ul class="nav navbar-nav">
        <li>@Html.ActionLink("Latest", "Latest", "Stores", routeValues: null, htmlAttributes: new { @style = "color:white;" })</li>
        <li>@Html.ActionLink("HowTo", "HowTo", "Shuttles", routeValues: null, htmlAttributes: new { @style = "color:white;" })</li>
        <li>@Html.ActionLink("Contact Us", "ContactUsPublic", "Stores", routeValues: null, htmlAttributes: new { @style = "color:white;" })</li>
      @*<li>@Html.ActionLink("Pick something", "PickSomething", "Stores", routeValues: null, htmlAttributes: new { @style = "color:white;" })</li>*@
    </ul>
    }

    @Html.Partial("_LoginPartial")

    </div>
}

希望这会有所帮助......