4

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.com/home/index
Visible: www.example.com/results
KyleMit
  • 30,350
  • 66
  • 462
  • 664
chuckd
  • 13,460
  • 29
  • 152
  • 331
  • One possible option would be to assign a value to `ViewBag` and include/exclude the html based on its value - `@if(ViewBag.CanDisplay) {..` –  Feb 01 '15 at 05:22
  • Since your `navbar` is on master/layout page...why not to check the condition there and display the input accordingly. – Vijay Feb 01 '15 at 05:34
  • How would I check the condition on the master page/layout? – chuckd Feb 01 '15 at 05: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 Feb 01 '15 at 13:53
  • I'm using @if(ViewBag.CanDisplay) to hide data currently – chuckd Feb 02 '15 at 05:48

1 Answers1

7

In 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:

Community
  • 1
  • 1
KyleMit
  • 30,350
  • 66
  • 462
  • 664