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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:47:00+00:00 2026-05-30T04:47:00+00:00

So right now I have two routes: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, //

  • 0

So right now I have two routes:

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

           routes.MapRoute(
               "Legos",
               "{controller}/{action}/{page}",
               new { controller = "Legos", action = "Lego", page = UrlParameter.Optional });

If I go to www.website.com, I will be able to see my homepage just fine, but my Legos route doesnt work. Like-wise, if I put my Legos route on top, I can go to www.website.com/Legos/Lego/1 just fine, but going to http://www.website.com thows an error(below), and I need to manually go to www.website.com/Home/Index to see my homepage.

Error:

The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Errors(Int32, System.String)' in 'stuff.Controllers.Legos'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

Why would this be?

  • 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-30T04:47:01+00:00Added an answer on May 30, 2026 at 4:47 am

    The reason is that both routes have the same number of parameters and no constraints, so the route handler cannot differentiate between them for an inbound request – it will just go with the first match (i.e. whichever has been added to the route table first).

    If you correctly differentiate between your routes then it will work. For example, you could try removing the “id” optional parameter from the “Default” route and making the “page” part of the “Legos” route mandatory (as it appears that it is required for the endpoint to work, this is best practice anyway):

    routes.MapRoute(
        "Legos",
        "{controller}/{action}/{page}",
        new { controller = "Legos", action = "Lego", page = 1 });
    
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}", // URL with parameters
        new { controller = "Home", action = "Index" } // Parameter defaults
    );
    

    This would mean that a url with two parameters (i.e. Home/Index) would not match the “Legos” route, as it is missing the required “page” parameter – it would then test the “Default” route, which would succeed as “Home/Index” matches the “{anything}/{anything}” format it expects.

    Your other option would be to add a route constraint to one of the routes – for example you could make “page” only accept numbers, so if the incoming request looked like {anything}/{anything}/{numeric} it would match the “Legos” route, but if it was non-numeric it wouldn’t match the constraint and would instead hit the default route:

    routes.MapRoute(
    "Legos",
    url: "{controller}/{action}/{page}",
    defaults: new { controller = "Legos", action = "Lego" },
    constraints: new { page = @"([0-9]+)" } ); // constrain to "one or more numbers" - constraints are simply regular expressions
    
    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
    

    Of course the “problem” with this particular solution would be if you had a numeric id (which lets face it, most are) that you wanted to use for the “default” route, it would end up being caught by the “Legos” route…

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

Sidebar

Related Questions

Right now, I have two Eclipse projects - they both use Maven 2 for
I actually have right now two questions: 1) What font faces are preferred for
Right now I have a few new applications being developed against an Oracle Database,
Right now I have two buttons. Each one needs to produce a different sound.
Right now I have two fields for cost. One for dollars and one for
Right now I have two repeaters: 1 will be shown when the page loads,
Right now I have two different groups of users on my site: customers and
Right now I have two tables for getting a timeline of posts that a
Right now I have two activities. My goal is to allow the user to
Right now I have two .java files. The Main.java: public class Main { static

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.