title: trying to implement a search in .net MVC
body: <p>I am having a tough time figuring out how to do this.  I have added a search box to the main page of my site.  The site has various products you can buy divided into categories.  When you click one of the categories(for instance Candles and Scents), it takes you to /Home/Products/candles-scents.  Now I have created new methods in my controller and model which correctly do the search.  My search function is basically duplicating my "product categories" function, only the sql query is modified.  So I want the site to go to the products page again, just like for a specific category: /Home/Products/"search".  I'm not sure if I should wrap my search box in a form or if there is a better way.  Right now I am trying jquery ajax, but of course the page is not getting redirected.</p>
  
  <p>Here is my search box html:</p>
  
  <pre><code>&lt;input type="text" class="search" placeholder="search" onfocus="this.placeholder = ''" onblur="this.placeholder = 'search'"/&gt;
  </code></pre>
  
  <p>And here is my jquery:</p>
  
  <pre><code>$(".search").keypress(function (event) {
          var searchString = $(this).val();
          console.log(searchString);
          console.log("blah");
          if (event.which == 13) {
              $.ajax({
                  url: '@Url.Action("_search", "Home")',
                  data: {
                      search: searchString
                  }
              })
          }
      });
  </code></pre>
  
  <p>And here is the _search function in the controller:</p>
  
  <pre><code>public ActionResult _search(string search)
      {
  
          // get the model
          List&lt;ProductModel&gt; m = new List&lt;ProductModel&gt;();
  
          m = ProductsModel.getProductsBySearch(search);
  
          return View(m);
      }
  </code></pre>
  
  <p>Then that function simply calls runs the sql query and returns a list of appropriate ProductModel's.  I have the backend stuff figured out.  I am just not sure how to correctly call my search from the front end.</p>