title: ASP.NET MVC - How to page ajax search results?
body: <p>I am struggling to get to grips with a particular form setup in my asp.net MVC application.
  Currently I have a page which displays a chunk of data. On this page is a simple form that calls into an action method that returns a partialview when posted (through ajax - jform).
  This is all very well until I try and add paging support to the search results.</p>
  
  <p>I have a chunk of code that that will paginate an IQueryable, but Im not sure how to implement this in my current setup.</p>
  
  <p>Heres some code:</p>
  
  <pre><code>[Authorize]
          public ActionResult AssetSearch(string RoomID, string type, string keyword, string risks)
          {
  
              //check values passed in
              Guid? r = null;
              if (RoomID != "Any" &amp;&amp; RoomID != null)
                  r = new Guid(RoomID);
  
              string t = type == "Any" ? null : type;
              string risk = risks == "Any" ? null : risks;
  
              var assets = surveyRepository.GetAssetsSearch(r, t, keyword, risk);
  
              if (Request.IsAjaxRequest())
              {
                  return PartialView("AssetListControl", assets);
              }
              else
              {
                  return View("AssetListControl", assets);
              }
          }
  </code></pre>
  
  <p>This action method returns a partial view which gets rendered out in a div through the following jquery.</p>
  
  <pre><code>$(document).ready(function() {
          $("#searchForm").submit(function() {
              $("#searchForm").ajaxSubmit({ target: '#results', beforeSubmit: PreSub, success: Success });
              return false;
          });
      });
  
      function Success(responseText, statusText) {
          $("#loadingMessage").html("done");
          $('#resultsTable').tablesorter();
          $("#results").slideDown("slow");
      }
  
      function PreSub(formData, jqForm, options) {
          $("#loadingMessage").html("loading...").fadeIn();
          $("#results").slideUp("fast");
          return true;
      }
  </code></pre>
  
  <p>And my form looks as follows:</p>
  
  <pre><code>&lt;form id="searchForm" action="&lt;%=Url.Action("AssetSearch") %&gt;" method="post"&gt;
      &lt;fieldset&gt;
          &lt;label for="RoomID"&gt;
              Room Name&lt;/label&gt;
          &lt;%= Html.DropDownList("RoomID") %&gt;
          &lt;label for="Type"&gt;
              Asset Type&lt;/label&gt;
          &lt;%= Html.DropDownList("Type") %&gt;
          &lt;label for="Risks"&gt;
              Risk Level&lt;/label&gt;
          &lt;%= Html.DropDownList("Risks") %&gt;
          &lt;label for="Keyword"&gt;
              Keyword&lt;/label&gt;
          &lt;%= Html.TextBox("Keyword") %&gt;
      &lt;input type="submit" name="sumbit" id="searchBtn" value="Search" /&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Sorry for the code overload :-)</p>
  
  <p>I have a feeling that I have configured my controller and view in such a way that paging won't be easy to implement. All advice welcome!</p>
  
  <p>Thanks in advance!</p>