title: How to save query values when searching? ASP.NET MVC
body: <p>I have such an action method:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Get)]
  public ActionResult Search(String filter, String value, Int32? page) {
      var set = new List&lt;Employee&gt;();
      switch(filter) {
      case "by-name": {
              set = this.repository.Get(
                  e =&gt; (e.LastName + " " + e.FirstName + " " + e.MiddleName) == value
              ).ToList();
              break;
          }
          case "by-empn": {
              set = this.repository.Get(
                  e =&gt; e.EmployeeNumber == value
              ).ToList();
              break;
          }
          default: return RedirectToAction("Search", "Employee"); 
      }
  
      ViewBag.SearchedEmployees = set.Count();
      return View(set.ToPagedList(page ?? 1, PageSize));
  }
  </code></pre>
  
  <p>Search view is like this:</p>
  
  <pre><code>@if(Model.Count &gt; 0) {
      foreach(var item in Model) {
          Html.RenderPartial("Employee.Card", item);
      }
  
      @Html.PagedListPager(
          Model,
          page =&gt; Url.Action("Search", new { page = page }),
          new PagedListRenderOptions {
              LinkToFirstPageFormat = "&lt;&lt; Beginning",
              LinkToPreviousPageFormat = "&lt; Back",
              LinkToNextPageFormat = "Forth &gt;",
              LinkToLastPageFormat = "End &gt;&gt;"
          }
      )
  }
  </code></pre>
  
  <p>Search form is presented as a partial view:</p>
  
  <pre><code>@using(Html.BeginForm("Search", "Employee", FormMethod.Get, new { @class = "search-form" }))
  {
      &lt;p&gt;
          @Html.TextBox("value")
      &lt;/p&gt;
      &lt;p&gt;
          @Html.RadioButton("filter", "by-name", true) By name &lt;br/&gt;
          @Html.RadioButton("filter", "by-empn") By empn &lt;br/&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;input type="image" src="@Url.Content("~/Content/Images/Search.png")" /&gt;
      &lt;/p&gt;
  }
  </code></pre>
  
  <p>Problem: I have <code>N</code> page links. When I try to go to the second page I face an infinite loop of redirects. That's the way I implemented my action - default case is fired. So <code>filter/value</code> values are <code>null</code> on the second action call? Why? 
  How do I refactor my search action?</p>
  
  <p>Also how should I configure route for such an action?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So should route for the search action look like:</p>
  
  <pre><code>routes.MapRoute(
      null,
      "{controller}/{action}/Page{page}/filter{filter}/val{value}",
      new { controller = "Employee", action = "Search" }
  );
  </code></pre>
  
  <p>?</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>So it is possible to write next:</p>
  
  <pre><code>page =&gt; Url.Action("Search", new { filter = ViewBag.SearchFilter, value = ViewBag.SearchValue, page = page }),
  </code></pre>
  
  <p>And inside a controller:</p>
  
  <pre><code>public ActionResult Search(String filter, String value, Int32? page) {
  
      ViewBag.SearchFilter = filter;
      ViewBag.SearchValue = value;
      // ...
  }
  </code></pre>
  
  <p>Is this right?</p>