admin管理员组文章数量:1400863
I have a bootstrap navbar at the top of my page main page and inside it is a text input. I want it hidden until a search is performed and the user sees the results in the results
controller .
This is inside my bootstrap navbar.
<input type="text" class="form-control" placeholder="Search">
For example:
Hidden: www.example/home/index
Visible: www.example/results
I have a bootstrap navbar at the top of my page main page and inside it is a text input. I want it hidden until a search is performed and the user sees the results in the results
controller .
This is inside my bootstrap navbar.
<input type="text" class="form-control" placeholder="Search">
For example:
Hidden: www.example./home/index
Visible: www.example./results
Share
Improve this question
edited Feb 1, 2015 at 15:14
KyleMit♦
30.8k72 gold badges511 silver badges702 bronze badges
asked Feb 1, 2015 at 5:18
chuckdchuckd
14.7k34 gold badges179 silver badges396 bronze badges
5
-
One possible option would be to assign a value to
ViewBag
and include/exclude the html based on its value -@if(ViewBag.CanDisplay) {..
– user3559349 Commented Feb 1, 2015 at 5:22 -
Since your
navbar
is on master/layout page...why not to check the condition there and display the input accordingly. – Vijay Commented Feb 1, 2015 at 5:34 - How would I check the condition on the master page/layout? – chuckd Commented Feb 1, 2015 at 5:40
- So this has nothing to do with bootstrap perse, the question is two part. 1. How to pass info from a controller to the shared layout, and 2 How to toggle the visibility of an element based on a property. What have you tried so far regarding either of those? – KyleMit ♦ Commented Feb 1, 2015 at 13:53
- I'm using @if(ViewBag.CanDisplay) to hide data currently – chuckd Commented Feb 2, 2015 at 5:48
1 Answer
Reset to default 7In this case, you actually don't need to pass any specific information from the controller to the shared layout.
The shared layout can inspect the current route and the behave accordingly.
@if (ViewContext.RouteData.Values["Controller"].ToString() == "results")
{
<input type="text" class="form-control" placeholder="Search">
}
More Info:
- Passing data to Master Page in ASP.NET MVC
- Get Current View's Url with HtmlHelper in ASP.NET MVC 3
- How to show/hide an area within Razor View in ASP.NET MVC programmatically
本文标签: javascriptHow do I hide an element in the shared layout based on the controller in MVCStack Overflow
版权声明:本文标题:javascript - How do I hide an element in the shared layout based on the controller in MVC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744275495a2598392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论