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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:44:53+00:00 2026-05-23T15:44:53+00:00

Why would this route result in 404 Not Found when hitting url /users/3 to

  • 0

Why would this route result in 404 Not Found when hitting url /users/3 to call upon the route with a page number only in ASP.NET MVC:

routes.MapRoute(
    "Users", // Route name
    "users/{page}/{sortColumn}/{sortDirection}", // URL with parameters
    new { controller = "User", action = "Index", page = UrlParameter.Optional, sortColumn = UrlParameter.Optional, sortDirection = UrlParameter.Optional }, // Parameter defaults
    new { page = @"\d+", sortColumn = @"[\w-]+", sortDirection = @"asc|desc" } // Route constraints
);

Shouldn’t it be okay for me to load the route simply with the page parameter specified, as the sortColumn and sortDirection parameters are both set to UrlParameter.Optional?

Update:

Ok after digging up another StackOverflow answer on a similar topic, it appears if you choose to have an optional route, the constraint must also be optional. So changing my route constraints to:
new { page = @"\d*", sortColumn = @"[\w-]*", sortDirection = @"(asc|desc)?" }
which simply tests for zero or more matches makes my pages load up on all accounts.

However, if I try to make a route link that reflects that (@Html.RouteLink("test 2", "Users", new { page = 2 })), the hyperlink is generated as /users not /users/2! Strange thing though, if I manually hit /users/2 then the RouteLink is written as /users/2 lol Argh! 🙂

Perhaps I do have to make separate routes, but this is really not desirable as I don’t want to have to call upon differently named routes in Html.RouteLink()….
Thoughts?

  • 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-23T15:44:54+00:00Added an answer on May 23, 2026 at 3:44 pm

    Because you provide two parameters, but it expects 3 optional ones.. so it does not know which one is missing …

    In general you cannot use two consecutive optional parameters.

    References

    • http://weblogs.asp.net/imranbaloch/archive/2010/12/26/routing-issue-in-asp-net-mvc-3-rc-2.aspx
    • http://connect.microsoft.com/VisualStudio/feedback/details/630568/url-routing-with-two-optional-parameters-unspecified-fails-on-asp-net-mvc3-rc2
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would this be a proper way to dispose of a BackGroundWorker? I'm not sure
Under what circumstances would this or would this not be safe? I have a
This would be my issue I have a drop down that's not displaying fully.
This issue only exists under IIS5.1. I have found a way of resolving the
Would this work on all platforms? i know windows does \r\n, and remember hearing
Comment on Duplicate Reference: Why would this be marked duplicate when it was asked
For a login system in php would this be a suitable outline of how
I have read that you can do it, but would this really improve performance
This would be a question for anyone who has code in the App_Code folder
This would be very handy as typecasting gets boring fast.

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.