javascript - 如何在特定网站中隐藏 MVC 的部分视图
问题描述
我在 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>
解决方案
您可以从此代码中使用隐藏和显示登录/注销部分:
@if(User.Authenticated)
{ Html.RenderPartial("LogOnForm");}
并显示部分:
@if(!User.Authenticated)
{ Html.RenderPartial("LoginForm");}
推荐阅读
- ruby-on-rails - form_for 嵌套属性:创建不保存到数据库
- python - 未知速记标志:-E 中的“E”
- c# - 尝试将图像链接作为字符串传递给 POST 网络请求以发送到 API
- json - 在 SQL Server 2016 中使用 JSON 的两列字符串聚合
- output - 为什么随机森林从相同的输入生成不同的输出
- db2 - 在 Function 中使用 Unpivot
- python - 将 python 应用程序打包到 deb 中会抑制虚拟环境的使用吗?
- java - 复合模式:根是简单的复合吗?
- php - Symfony DI:在包构建期间访问编译器传递的配置参数
- php - 如何通过 android 中的改造从 php 中检索“字符串响应”?