Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在特定网站中对MVC隐藏部分视图_Javascript_Html_Model View Controller_Partial Views - Fatal编程技术网

Javascript 如何在特定网站中对MVC隐藏部分视图

Javascript 如何在特定网站中对MVC隐藏部分视图,javascript,html,model-view-controller,partial-views,Javascript,Html,Model View Controller,Partial Views,我在MVC中使用部分视图在GeneralYout中显示登录表单,但我想在特定网站上隐藏此登录表单。我没有找到合适的解决方案,在这里尝试了很多例子: @if (window.location.href == 'Index/Map' || window.location.href == 'Index/Game') { $("#PartialView").hide(); } 或者这个: var pathname = window.location.pathname; console.log(

我在MVC中使用部分视图在GeneralYout中显示登录表单,但我想在特定网站上隐藏此登录表单。我没有找到合适的解决方案,在这里尝试了很多例子:

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

@if(PlayerSession.AppPlayerSession.IsLoged)
{
Html.RenderPartial(“LogOnForm”);
}
其他的
{
登录
}

您可以使用此代码隐藏和显示登录/注销部分:

@if(User.Authenticated)
{ Html.RenderPartial("LogOnForm");}
并显示部分:

 @if(!User.Authenticated)
{ Html.RenderPartial("LoginForm");}

这应该从后端处理,而不是从javascript处理。我建议创建一个HtmlExtension来决定哪些操作结果应该显示或隐藏loggin按钮,并添加一个if logic with RazorYou not checking websites,you checking page on a single website。请具体说明你的意思,并注意你使用的词语。