我正在MVC中使用局部视图在GeneralLayout中显示登录表单,但是我想在特定网站上隐藏此登录表单。我没有为此找到合适的解决方案,在这里尝试了许多示例:
@if (window.location.href == 'Index/Map' || window.location.href == 'Index/Game') {
$("#PartialView").hide();
}
或者这个:
var pathname = window.location.pathname;
console.log(pathname);
switch (pathname) {
case "Index/Map":
$("#PartialView").hide();
break;
case "Index/Game":
$("#PartialView").hide();
break;
我的代码如下:
<div class="main-content" id="HideButtons">
<a id="logo" href="@Url.Action("Index", "Index")"></a>
@if (PlayerSession.AppPlayerSession.IsLogged)
{
Html.RenderPartial("LogOnForm");
}
else
{
<button class="button" id="logIn">Log In</button>
}
</div>
答案 0 :(得分:0)
您可以使用此代码隐藏和显示登录/注销部分:
@if(User.Authenticated)
{ Html.RenderPartial("LogOnForm");}
并显示部分内容:
@if(!User.Authenticated)
{ Html.RenderPartial("LoginForm");}