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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:30:25+00:00 2026-06-09T11:30:25+00:00

Just when I think I have routing figured out, it doesn’t work the way

  • 0

Just when I think I have routing figured out, it doesn’t work the way I think it should. I’m using ASP.Net MVC 4 RC. Here’s my RouteConfig:

        routes.MapRoute
        (
            "TwoIntegers",
            "{controller}/{action}/{id1}/{id2}",
            new { controller = "Gallery", action = "Index", id1 = new Int32Constraint(), id2 = new Int32Constraint() }
        );

        routes.MapRoute
        (
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

Here’s my route constraint:

public class Int32Constraint : IRouteConstraint
{
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        if (values.ContainsKey(parameterName))
        {
            int intValue;
            return int.TryParse(values[parameterName].ToString(), out intValue) && (intValue != int.MinValue) && (intValue != int.MaxValue);
        }

        return false;
    }
}

/{domain.com}/PageSection/Edit/21

It is getting stopped at the “TwoIntegers” route. It’s very clear there’s not a second integer being passed.

Here’s my error:

The parameters dictionary contains a null entry for parameter ‘id’ of
non-nullable type ‘System.Int32’ for method
‘System.Web.Mvc.ActionResult Edit(Int32)’ in
‘SolutiaConsulting.Web.ContentManager.Controllers.PageSectionController’.
An optional parameter must be a reference type, a nullable type, or be
declared as an optional parameter. Parameter name: parameters

What am I doing wrong? I have the more specific route listed first. Please help.

  • 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-06-09T11:30:26+00:00Added an answer on June 9, 2026 at 11:30 am

    Your constraints are not correctly specified. Make sure you are using the correct overload of the MapRoute extension method:

    routes.MapRoute(
        "TwoIntegers",
        "{controller}/{action}/{id1}/{id2}",
        new { controller = "Gallery", action = "Index" },
        new { id1 = new Int32Constraint(), id2 = new Int32Constraint() }
    );
    

    Notice the 4th argument that is used to specify constraints, not the 3rd.

    Btw, you could make your code more readable using named parameters:

    routes.MapRoute(
        name: "TwoIntegers",
        url: "{controller}/{action}/{id1}/{id2}",
        defaults: new { controller = "Gallery", action = "Index" },
        constraints: new { id1 = new Int32Constraint(), id2 = new Int32Constraint() }
    );
    

    Also how about a regex?

    routes.MapRoute(
        name: "TwoIntegers",
        url: "{controller}/{action}/{id1}/{id2}",
        defaults: new { controller = "Gallery", action = "Index" },
        constraints: new { id1 = @"\d+", id2 = @"\d+" }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried every way I can think of with this, but just not
I'm using ASP.NET MVC Preview 4 and would like to know how to use
This is going to sound quite bizarre. I have one ASP .NET MVC 2
I have read much information about agile and waterfall and I just cannot think
Really quick here... I think I have the answer, but just looking for some
I think I may have encountered a bug in mysql, or is it just
I have just one cs file in my repository which Git seems to think
I've been thinking about this and I just can't think of a way to
I am just learning Rails. I had encountered a routing error, though I think
We have a load balanced (NLB) ASP.NET web app which sends email. The servers

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.