title: MVC - Route with querystring
body: <p>After following <a href="http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc-4-and-visual-studio-2011/examining-the-details-and-delete-methods" rel="nofollow">this</a> MVC 4 tutorial series I was trying some of the stuff myself.
  I started by trying to make the searchfilter url friendly. The following code is what I'm using at the moment:</p>
  
  <p><strong>Global.asax</strong></p>
  
  <pre><code> public static void RegisterRoutes(RouteCollection routes)
          {
              routes.MapRoute(
                 name: "MovieSearch",
                 url: "Movies/SearchIndex/{movieGenre}/{searchString}",
                 defaults: new { controller = "Movies", action = "SearchIndex", movieGenre = UrlParameter.Optional, searchString = UrlParameter.Optional }
             );
  
              routes.MapRoute(
                  name: "Default",
                  url: "{controller}/{action}/{id}",
                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
              );           
          }
  protected void Application_Start()
          {
                  RegisterRoutes(RouteTable.Routes);
          }
  </code></pre>
  
  <p><strong>SearchIndex.cshtml</strong></p>
  
  <pre><code>&lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  
      @using (Html.BeginForm("SearchIndex", "Movies", FormMethod.Get))
      {   
           &lt;p&gt;  Genre: @Html.DropDownList("movieGenre", "All")
                Title: @Html.TextBox("searchString")&lt;br /&gt; 
           &lt;input type="submit" value="Filter" /&gt;&lt;/p&gt;
          }
  &lt;/p&gt;
  </code></pre>
  
  <p><strong>MoviesController.cs</strong></p>
  
  <pre><code>        //
          // GET: /Movies/SearchIndex/Comedy/Sherlock
          public ActionResult SearchIndex(string movieGenre, string searchString)
          {
              var GenreList = new List&lt;string&gt;();
  
              var GenreQry = from d in db.Movies
                             orderby d.Genre
                             select d.Genre;
  
              GenreList.AddRange(GenreQry.Distinct());
              ViewBag.movieGenre = new SelectList(GenreList);
  
              var movies = from m in db.Movies
                           select m;
  
              if (!string.IsNullOrEmpty(searchString))
              {
                  movies = movies.Where(s =&gt; s.Title.Contains(searchString));
              }
  
              if (string.IsNullOrEmpty(movieGenre))
              {
                  return View(movies);
              }
              else
              {
                  return View(movies.Where(m =&gt; m.Genre == movieGenre));
              }
          }
  </code></pre>
  
  <p>Now everything goes well when I put the following url in my adressbar: <strong>/Movies/SearchIndex/Comedy/Sherlock</strong></p>
  
  <p>But when I filter with the "filter" button in the SearchIndex.cshtml I get the following url: <strong>/Movies/SearchIndex?movieGenre=Comedy&amp;searchString=Sherlock</strong></p>
  
  <p>Anyone knows the problem here?</p>