我的页面主页顶部有一个 Bootstrap 导航栏,里面是一个文本输入。我希望它隐藏直到执行搜索并且用户在 results
controller 中看到结果。
这是在我的 Bootstrap 导航栏中。
<input type="text" class="form-control" placeholder="Search">
例如:
Hidden: www.example.com/home/index
Visible: www.example.com/results
最佳答案
在这种情况下,您实际上不需要将任何特定信息从 Controller 传递到共享布局。
共享布局可以检查当前路由和相应的行为。
@if (ViewContext.RouteData.Values["Controller"].ToString() == "results")
{
<input type="text" class="form-control" placeholder="Search">
}
更多信息:
关于javascript - 如何基于 MVC 中的 Controller 隐藏共享布局中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28259739/