Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:38:16+00:00 2026-05-31T16:38:16+00:00

After following this MVC 4 tutorial series I was trying some of the stuff

  • 0

After following this 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:

Global.asax

 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);
        }

SearchIndex.cshtml

<p>
    @Html.ActionLink("Create New", "Create")

    @using (Html.BeginForm("SearchIndex", "Movies", FormMethod.Get))
    {   
         <p>  Genre: @Html.DropDownList("movieGenre", "All")
              Title: @Html.TextBox("searchString")<br /> 
         <input type="submit" value="Filter" /></p>
        }
</p>

MoviesController.cs

        //
        // GET: /Movies/SearchIndex/Comedy/Sherlock
        public ActionResult SearchIndex(string movieGenre, string searchString)
        {
            var GenreList = new List<string>();

            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 => s.Title.Contains(searchString));
            }

            if (string.IsNullOrEmpty(movieGenre))
            {
                return View(movies);
            }
            else
            {
                return View(movies.Where(m => m.Genre == movieGenre));
            }
        }

Now everything goes well when I put the following url in my adressbar: /Movies/SearchIndex/Comedy/Sherlock

But when I filter with the “filter” button in the SearchIndex.cshtml I get the following url: /Movies/SearchIndex?movieGenre=Comedy&searchString=Sherlock

Anyone knows the problem here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:38:18+00:00Added an answer on May 31, 2026 at 4:38 pm

    When you use form method=”get”, your browser will join your form fields together into a long querystring. This has nothing to do with MVC itself. A couple of solutions:

    1. Handle the form submission event client-side, and re-create the url as you see fit.
    2. Create a custom route provider that 301 redirects your querystring back to a “friendly” url.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After following the steps outline in this Fluent NHibernate tutorial I am stuck on
After hours I am giving up on debugging the following: This works: URL[] urls
After following the RoR getting started tutorial, I added another model as: $ rails
I have this following mvc application The problem is when Im trying to assign
I am following this tutorial http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-9 (not exactly same as this) I am trying
After resolving issues with RIA installation here , I'm still getting this following error.
Hoping for some help after reading into MVC routing and not coming up with
To me, this seems to make little sense, but after reading the information in
I'm trying to do the tutorial here: http://www.asp.net/entity-framework/tutorials/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application In the ActionResult Edit, I have
I'm not sure if this is possible in Spring MVC 3.0, but I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.