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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:44:45+00:00 2026-05-24T16:44:45+00:00

I defined the a new route (see below). When I launch the application, I’d

  • 0

I defined the a new route (see below). When I launch the application, I’d like by default:

  • Go Home/Index
  • If I go to /Customer/Detail/MyCode get “MyCode”

When I use this configuration, I start on Home/Index it’s ok but /Customer/Detail/MyCode give a null value all the time.

If I inverse the routes.MapRoute, I have :

  • By default I go to /Customer/Detail and I get mycode value all the time (no null anymoe)
  • I don’t start on /Home/Index

Any idea ?

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

routes.MapRoute(
    "CustomerDetail",
    "{controller}/{action}/{code}",
    new { controller = "Customer", action = "Detail", code = UrlParameter.Optional }
);
  • 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-24T16:44:46+00:00Added an answer on May 24, 2026 at 4:44 pm

    A single route will be enough:

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

    When you request Home/Index this will invoke the Index action on HomeController and pass null as the code parameter and when you request Customer/Detail/MyCode the Detail action will be invoked on CustomerController and passed code=MyCode.

    The reason you were getting null is that both your routes are equivalent, meaning that they are of the form Controller/Action/SomeCode which means that for both urls the first route is matched, but the parameter is called id instead of code so you are getting code=null. Another possibility is to simply leave the default route as is:

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

    and then rename the parameter to the Detail action to id:

    public ActionResut Detail(string id)
    {
        // if you request Customer/Detail/MyCode the id parameter will equal MyCode
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have defined a route as below: context.MapRoute(SearchEngineWebSearch, search/web/{query}/{index}/{size}, new { controller = search,
I have the following route defined routes.MapRoute( ItemName, {controller}/{action}/{projectName}/{name}, new { controller = Home,
At the moment I have just this route defined routes.MapRoute( Default, {controller}/{action}/{id}, new {
I have my default route defined like this routes.MapRoute( Default, // Route name {controller}/{action}/{id},
Suppose I have defined route like that, context.MapRoute( Preview, /preview/{id}/{type}, new { controller =
I have a route defined like this: routes.MapRoute(Date, Date/{year}/{month}/{day}, new { controller = Date,
Let's say I have defined a route: routes.Add(new Route(Users/{id}, new MvcRouteHandler()) { Defaults =
I've defined the following route for a simple blog. routes.MapRoute( Blog, blog/{year}/{month}/{day}, new {
I have a script which creates a user-defined object like this: obj = new
I have a route defined with several hardcoded (non-parameter) segments: routes.MapRoute(null, suggestion/list/by/{tag}, new {

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.