title: ASP.NET MVC 5 - Partial view doesn't work with my AJAX live search
body: <p>I have the following problem</p>
  
  <p>In my ASP.NET MVC 5 app I want to list all users and have a live search bar that updates as you type. I made it and it works, but it doesn't return a partial view, instead it returns a whole new page like so.</p>
  
  <p>This is the page that lists all the users:
  <a href="https://i.stack.imgur.com/lDA14.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lDA14.png" alt="enter image description here"></a>
  And this is what I get when I search
  <a href="https://i.stack.imgur.com/fNtek.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fNtek.png" alt="enter image description here"></a></p>
  
  <p>This is my controller(AdminController.cs)</p>
  
  <pre><code>   public class AdminController : Controller
  {
      protected readonly ApplicationDbContext db = new ApplicationDbContext();
  
      public ActionResult Index()
      {
          return View();
      }
  
      public ActionResult Users()
      {
          var users = db.Users.ToList();
  
          return View(users);
      }
  
      public ActionResult Search(string query)
      {
          var result = db.Users.Where(u =&gt; u.UserName.ToLower().Contains(query.ToLower())).ToList();
  
          return PartialView("_UsersResult", result);
      }
  }}
  </code></pre>
  
  <p>My View(Users.cshtml)</p>
  
  <pre><code>@model List&lt;Forum.Models.ApplicationUser&gt;
  
  
  
  @using (Ajax.BeginForm("Search", null,
      new AjaxOptions
      {
          HttpMethod = "GET",
          UpdateTargetId = "results",
          InsertionMode = InsertionMode.Replace
      }, new {id = "searchForm"}))
  {
      &lt;input name="query" placeholder="Search" oninput="$('#searchForm').submit()"/&gt;
      &lt;input type="submit" value="Search"/&gt;
  }
  
  
  &lt;div id="results"&gt;
  @Html.Partial("_UsersResult", Model)
  &lt;/div&gt;
  </code></pre>
  
  <p>And my Partial View(_UsersResult.cshtml)</p>
  
  <pre><code>@model List&lt;Forum.Models.ApplicationUser&gt;
  
  @foreach (var user in Model)
  {
      &lt;h3&gt;@user.UserName&lt;/h3&gt;
  }
  </code></pre>