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

  • Home
  • SEARCH
  • 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 824835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:09:29+00:00 2026-05-15T03:09:29+00:00

I want to define a route that have 2 optional parameters in the middle

  • 0

I want to define a route that have 2 optional parameters in the middle of the URL the start an end parameters are digits

routes.MapRoute(
                "",
                "Source/Changeset/{start}/{end}/{*path}",
                new {
                        controller = "Source",
                        action = "Changeset",
                        start = UrlParameter.Optional,
                        end = UrlParameter.Optional, 
                        path = "crl"
                    },
                new { start = @"\d+", end = @"\d+" }
                );

i tried diferent approaches and none of them worked, i could use some of your help.

Thanks in advance.

EDIT

I manage to solve the problem this way, but it’s far from elegant.

routes.MapRoute(
                "",
                "Source/Changeset/{start}/{end}/{*path}",
                new {
                        controller = "Source",
                        action = "Changeset",
                        start = UrlParameter.Optional,
                        end = UrlParameter.Optional, 
                        path = "crl"
                    },
                new { start = @"\d+", end = @"\d+" }
                );  

            routes.MapRoute(
                "",
                "Source/Changeset/{start}/{*path}",
                new
                {
                    controller = "Source",
                    action = "Changeset",
                    start = UrlParameter.Optional,
                    path = "crl"
                },
                new { start = @"\d+" }
                );  

            routes.MapRoute(
                "",
                "Source/Changeset/{*path}",
                new
                {
                    controller = "Source",
                    action = "Changeset",
                    path = "crl"
                }
                );  
  • 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-15T03:09:30+00:00Added an answer on May 15, 2026 at 3:09 am

    you are going to need to make routes for all possible combinations, which can get a little hairy:

    //route if everything is included
    routes.MapRoute(null, ""Source/Changeset/{start}/{end}/{*path}",
        new { controller = "Home", action = "Index" }
    );
    
    //route if nothing is included
    routes.MapRoute(null, ""Source/Changeset/{*path}",
        new { controller = "Home", action = "Index", start=0, end=5 } //defaults
    );
    
    //and so on...
    

    But, there is also a problem here: since start and end are both digits, there would be no way (since they are optional) to decide if the ‘2’ in Source/Changeset/2/fodass is the start or end variable, so you may have to think up a new approach, or change yours to something like Source/Changeset/Start/2/fodass, Source/Changeset/End/5/fodass, Source/Changeset/Start/2/End/5/fodass, etc.

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

Sidebar

Related Questions

Suppose I have defined route like that, context.MapRoute( Preview, /preview/{id}/{type}, new { controller =
I have a defined route that displays a dynamic page: page_show: url: /:domain_slug/:slug class:
I want clean URLs and have defined two routes: routes.MapRoute( Search, Search, new {
I want to define a class that supports __getitem__ , but does not allow
I want to define a class method that has access to a local variable.
I want to define a constant that should be available in all of the
I want to define a global before filter that will run before every request
Is it possible to define a route in MVC that dynamically resolves the action
I want to be able to specify a base url for all my routes
Hello is it possible to have an ASP.NET MVC form that uses the routes

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.