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 6210993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:15:32+00:00 2026-05-24T06:15:32+00:00

I created the following route: routes.MapRoute( Notes 1, // Route name {book}-{id}, // URL

  • 0

I created the following route:

routes.MapRoute(
   "Notes 1", // Route name
   "{book}-{id}", // URL with parameters
   new { controller = "Notes", action = "Note", id = UrlParameter.Optional }
);

Using this URL and the MVC route checker:

http://127.0.0.1:81/java-abcd-efg

id < efg
book < java-abcd
controller < Notes
action < Note

What I expected was that book would contain “java” and id would contain “abcd-efg”. Can someone explain what’s wrong and why this isn’t the case.

Thanks

  • 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-24T06:15:33+00:00Added an answer on May 24, 2026 at 6:15 am

    The problem is that you didn’t tell MVC to expect more than one dash; so it grabbed what it found and tried to parse it that way.

    Well, that just sucks for us.

    If you know that your route will always be:

    {book}-{name}-{perhapsMoreName-{maybeEvenMore}
    

    Then we can handle that, but it’s going to take work on the server side to parse that.

    Believe me, it’d be much easier just to use slashes. If someone comes to you and complains about SEO, ask them to show you the exact place where it matters (And somehow why slashes don’t work as well). I’m not saying they’re wrong, but there’s a lot of, "I think it works this way with SEO" and that gets annoying, fast.

    I’m going to provide you with two solutions. Solution 1 would be the way I would handle it (and fight for) and solution 2 would be the solution to your particular problem with your current scheme for handling (and I’ve dealt with solution 2 in practice, and at best it is very icky).

    Solution 1

    Set up your routes similar to how Stack Overflow sets up theirs. This would allow your SEO guy to have his hallowed SEO, and you would get what you want: No ulcers.

    Your URLs would change to look like:

    http://example.com/books/id/book-type-name

    routes.MapRoute("bookRoute",
        "books/{id}/{*bookName}",
        new { controller = "Notes", action = Show, id = "", bookName = "" }
    );
    

    Then, you can use the bookName for display, but not actually use it to get any code. Just change your Show method to retrieve items by their Id.

    Solution 2

    This solution uses a ActionFilter to intercept the requests and parse out what’s what. It’s an icky solution, but it should work.

    I wrote an answer that showed this solution for another question. It is applicable here as well, just change the search type to query the database based on what’s in the URL. Also, the route will have to go at the bottom of your routes, otherwise it’ll catch that first. All the standard disclaimers apply: Use parameretized queries, or an ORM that parameteretizes them for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following route: routes.MapRoute( Default, // Route name {language}/{controller}/{action}/{id}, new { language
I've defined the following route: routes.MapRoute( null, foo/{id}/{title}, new { controller = Boo, action
I created this route: routes.MapRoute( _ Pages, _ Pages/{id}/{title}, _ New With {.controller =
I created the following route: routes.MapRoute( TestRoute4, // Route name Report {ref_id} Test Board,
SOLUTION the route routes.MapRoute( Whatever, // Route name {controller}/{action}/{id}, //{ID} MUST BE USED IN
I have the following route set up: context.MapRoute( MyAccount_default, MyAccount/{controller}/{action}/{id}, new { action =
I have the following setup for my application: routes.MapRoute(Default, {controller}/{action}/{idt}, new { controller =
I have created a new route like the following: routes.MapRoute( BlogYMD, blog/date/{year}/{month}/{day}, new {
I created the following route: map.todo todo/today, :controller => todo, :action => show_date Originally,
I have the following route configuration in a ASP.NET MVC4 project: routes.MapRoute( name: HttpError,

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.