title: ASP.NET MVC using WebGrid for showing SearchResults
body: <p>I have a Search.cshtml View, that looks like that:</p>
  
  <pre><code>@model IEnumerable&lt;MVC.Models.Books&gt;
  
  @using (Html.BeginForm())
  {
      @Html.DropDownList("Categorie", ViewBag.Categorie as SelectList); 
      @Html.TextBox("Query");
      &lt;input type="submit" value="Search" /&gt;
  }
  
  @if (this.Model.Any())
  {
      var grid = new WebGrid(Model, rowsPerPage:20);
  
      @grid.GetHtml(mode: WebGridPagerModes.All,
      columns: grid.Columns(
          grid.Column(columnName: "Number"),
          grid.Column(columnName: "Title"),
          grid.Column(format: (item) =&gt; Html.ActionLink("Edit", "Edit", new { id = item.Nummer })),
          grid.Column(format: (item) =&gt; Html.ActionLink("Details", "Details", new { id = item.Nummer })),
          grid.Column(format: (item) =&gt; Html.ActionLink("Delete", "Delete", new { id = item.Nummer }))
          )
      )
  }
  </code></pre>
  
  <p>My Controller has the following methods:</p>
  
  <pre><code>        public ActionResult Search()
          {
              ViewBag.Categorie= new SelectList(new[] { "Number", "Title"});
              IEnumerable&lt;Books&gt; model = new List&lt;Books&gt;();
              return View(model);
          }
  
          [HttpPost]
          public ActionResult Search(string categorie, string query)
          {
              ViewBag.Categorie= new SelectList(new[] { "Number", "Title"});    
              IEnumerable&lt;Books&gt; model;
  
              switch (categorie)
              {
                  case "Number":
                      int qnumber = Convert.ToInt32(query);
                      model = _db.Books.Where(b =&gt; b.Number == qnumber)
                                      .OrderBy(b =&gt; b.Number).ToList();
                      break;
                  default:
                      model = _db.Books.Where(b =&gt; b.Title.Contains(query))
                                      .OrderBy(b =&gt; b.Title).ToList();
                      break;
              }
              return View(model);
          }
  </code></pre>
  
  <p>Everything works almost fine. But the sorting of the Columns and the Paging-Links dont work. If you click on one of them, the View reloads with no data in the Grid.</p>
  
  <p>Is there any way to get the WebGrid work in this Search-View?</p>