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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:24:18+00:00 2026-06-18T00:24:18+00:00

I just began working on an application with a couple areas (basic grid master

  • 0

I just began working on an application with a couple areas (basic grid master / details type system..) I’m looking into taking advantage of the nice routing features in MVC (4 specifically) and I’m “just not getting it” I presume.

Currently the only route defined is the basic one:

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

which is fine, it works with the areas we have defined, so I’m assuming it must know where the user is and route to the appropriate controller based contextually on the location / area that the user is in.. so far nice..

Now, i’m trying to set up a new route that can handle

/someController/someAction/{statusName} 

and specifically something like:

/OrderManager/List/New 

AND

/OrderManager/List/Viewed

where “New” is the “New” status and have the Action Signature look like:

public ActionResult List(string statusName)

i was assuming I could just add the new route below the default one identifying “statusName” instead of Id, but of course, how the H would the routing mechanism know the difference between :

/controller1/action1/15

/controller2/action2/new

I did try adding a “static” route in the form of

routes.MapRoute("Default", 
            "ControllerName/ControllerAction/{statusName}", 
            new { statusName = UrlParameter.Optional }
        );

I thought I could “hiJack” just that one route and do something special with it, but to know avail, the router stops at first match?? I’m assuming that was the wrong way to address this issue anyhow..

so now I’m going through the idea of getting to something like:

/somecustomroutename/somesortValue

ex.
/OrderManagerList/viewNew

where these routes would basically be “aliases”. I had thought that adding the following route would do the trick:

 routes.MapRoute("Default_List",
          "OrderManagerList/{statusName}",
          new {controller="OrderManager", action="List", statusName= UrlParameter.Optional }
      );

with the associated action on the OrderManager controller:

public ActionResult List(string statusName)

no matter what I try, the argument is null, or the “resource cannot be found”

I know the controllers need to have a corresponding View file.. but that’s not the issue here, the issue is my attempt at understanding the routing..

SO my questions.. fundamentally, what am I missing about the routing in MVC (4)? even some good articles for a simpleton like myself to understand?

my understanding; define a route, and map it’s “endpoint”.. however, i think i’m not understanding the assumptions that the machine is making..

anyhow, let me know if further explain / edit is required..

thanks in advance.

  • 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-18T00:24:19+00:00Added an answer on June 18, 2026 at 12:24 am

    The basic principle of routes is that they are evaluated from the top down, and the routing systems uses the first match, not the best match.

    The implication of this is that you must order your routes in order of specificity, with the most specific route first and the most general route last.

    With this principle in mind, let’s look at your situation. Initially, you have only the default route defined:

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

    The URL pattern is “{controller}/{action}/{id}”. By itself, this would match any three-segment URL, and would not match any URL that had less than three segments. However, the third input parameter is the default parameter, which defines defaults for the first and second segment and indicates that the third segment is optional. The next effect of this is to make the route match URL having 0,1, 2 or 3 segments.

    Now you want to add a route where the third URL segment is mapped to a “statusName” parameter, and can handle URLs like:

    OrderManager/List/New 
    OrderManager/List/Viewed 
    

    There are two basic approaches you can take here. You can 1) create a very specific route that will handle these two URLs only, or 2) you can try and create a more general route to handle the general case. Let’s look at the first case first. You can create a route as follows:

    routes.MapRoute("", "OrderManager/List/{statusName}",
                  new { Controller = "OrderManager", Action = "List" });
    

    Note that because this route is more specific than the default route, you must put this route before the default route.

    If you want to have a more general route, you need to decide how this route will differ from the default route, since they both will match URLs having three segments. Let’s say you decide that the new route will accept anything that only contains letters in the third segment, leaving the default route to handle anything containing numbers. You can do this using route constraints. For example you could write a route as follows:

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                constraints: new { id = @"^\d+$" });
    
            routes.MapRoute(
                name: "NewRoute",
                url: "{controller}/{action}/{statusName}",
                defaults: new { Controller = "OrderManager", Action = "List" },
                constraints: new { statusName = "^[A-Za-z]+$" });
    

    With these two routes, any three-segment URL having only letters in the third segment will put the third segment into a variable called “statusName”, whereas any URL with an integer in the third segment will put the third segment into a variable called “id”.

    In any applications of real complexity, routes can get complicated, and it is very advantageous to write unit tests for your routes, to insure that you don’t screw things up when you add or modify a route.

    For good references on routing, see Scott Sanderson’s book or see the MSDN documentation

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

Sidebar

Related Questions

I just began looking into source control.... And installed subversion from collabnet... I also
I just began working on a little twitter-app using tweepy. is there any kind
So, I've just began playing around with the demo of Skeleton, the responsive grid
I have gotten my basic L-System working and I decided to try and optimize
I just began working with ASP.NET and I'm trying to bring with me some
Okay, so my application was working just fine until I decided to clean up
I have just begun working on a C# application (using log4net). I'm supposed to
For class I'm working on my first GUI application. It's just a simple image
I recently started working on a large complex application, and I've just been assigned
I've just began on a new application and I added a button which in

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.