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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:35:19+00:00 2026-06-10T00:35:19+00:00

I am trying to set up my MVC application with the root as follows:

  • 0

I am trying to set up my MVC application with the root as follows:

  • mysite.com/ -> Index action
  • mysite.com/thingID -> to CurrentThing action
  • mysite.com/thingID/year -> to CurrentThing action

Action: public ActionResult CurrentThing(string thingID, int year)

I also need the regular controller/action route to work both with and without an id. ThingID is a string. I have the following routes defined:

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

        routes.MapRoute(
            "RootSpecificRecord",
            "{thingID}/{year}",
            new { controller = "Things", action = "CurrentThing", year = DateTime.Now.Year }
        );

        routes.MapRoute(
            "Root",
            "",
            new { controller = "Things", action = "Index" }
        );

This works fine until I go to mysite.com/id/year at which point the first route treats the id as a controller and the year as an action. How can I resolve this?

  • 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-10T00:35:21+00:00Added an answer on June 10, 2026 at 12:35 am

    The routing engine is unable to tell the difference between

    /{controller}/{action}/{id} and /{ThingId}/{year}

    Since your id parameter is optional, and you don’t have any constraints that ThingId is an id.

    You could try putting the RootSpecificRecord route first, and altering the Id so that it will only accept an integer. This will make it so it’s more specific than your regular route. Assuming ofcourse that thingID is an integer, you could alter your route like this:

            routes.MapRoute(
                "RootSpecificRecord",
                "{thingID}/{year}",
                new { controller = "Things", action = "CurrentThing", year = DateTime.Now.Year },
                new {thingID= @".*\d+.*" }
            );
    

    See this blog post about route constraints, if you want to create a different constraint.

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

Sidebar

Related Questions

Consider following: $(#myform).attr({ action: @Url.Action(MVC.Thing.Delete().AddRouteValue(id, myJsModel.Id )) }); I'm trying to set the action
Hi guys I'm running through this tutorial: http://www.sencha.com/learn/a-sencha-touch-mvc-application-with-phonegap and trying to get the code
We're trying to set up Spring-Test-MVC for our Spring-MVC web app. We started out
I'm trying to set up a messages view with asp.net mvc that will display
I have a MVC application that I am now trying to add authentication and
I'm trying to create an authorization scheme for my ASP.NET MVC application where an
I am using subsonic to access my DB in a mvc application. When trying
We are having MVC application which reads data from MSMQ. We are trying to
I have a mixed WebForms/MVC application I'm trying to deploy to our staging environment,
I'm working on my first real MVC application and I'm trying to follow general

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.