title: How to call a search method in a _Layout.cshtml?
body: <p>I'm trying to create a search method, that is called in my _Layout.cshtml and when I click on submit button, the user is redirected to "search view".</p>
  
  <p>I' following this <a href="http://www.asp.net/mvc/overview/getting-started/introduction/adding-search" rel="nofollow">tutorial</a>, but the author call your method at index view and I need to call the method at _Layout to be redirect to another view that will give me the return of method.</p>
  
  <p>This is my _Layout, is basic a nav-bar from bootstrap with a textfield and a button, that the user can put what he need to find:</p>
  
  <pre><code>    @model IEnumerable&lt;TestTcc2.Models.Musica&gt;
  &lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;@ViewBag.Title&lt;/title&gt;
      &lt;link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      @Styles.Render("~/Content/Bootstrap")
      @Scripts.Render("~/bundles/modernizr")
      @Scripts.Render("~/bundles/jquery")
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="navbar navbar-inverse navbar-fixed-top"&gt;
          &lt;div class="container"&gt;
              &lt;div class="navbar-header"&gt;
                  &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;/button&gt;
                  &lt;a class="navbar-brand" href="#"&gt;@Html.ActionLink("your logo here", "IndexOuvinte", "Home")&lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="collapse navbar-collapse"&gt;
                  &lt;ul class="nav navbar-nav"&gt;
                      &lt;li&gt;@Html.ActionLink("Home", "IndexOuvinte", "Home")&lt;/li&gt;
                  &lt;/ul&gt;
                  &lt;form class="navbar-form navbar-left" role="search"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;input type="text" class="form-control" placeholder="Search"&gt;
                      &lt;/div&gt;
                          &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
                  &lt;/form&gt;
                  &lt;ul class="nav navbar-nav navbar-right"&gt;
                          &lt;li&gt;@Html.ActionLink("Manage Account", "Manage", "Account")&lt;/li&gt;
                          &lt;li&gt;@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" }))
                              {
                              @Html.AntiForgeryToken()
                              &lt;a href="javascript:document.getElementById('logoutForm').submit()"&gt;Log off&lt;/a&gt;}&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
              &lt;!--/.nav-collapse --&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  
  
      &lt;div class="container"&gt;
  
          @RenderSection("featured", required: false)
          @RenderBody()
  
      &lt;/div&gt;
      &lt;!--Fim container --&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is the method that I want to call at _Layout.cshtml:</p>
  
  <pre><code>public ActionResult Search(string search)
          {
              var musicas = from m in db.Musicas select m;
  
              if (!String.IsNullOrEmpty(search))
              {
                  musicas = musicas.Where(s =&gt; s.Nome.Contains(search));
                  return RedirectToAction("Search"); //name of view that will return the data
              }
              return View(musicas);
          }
  </code></pre>