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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:24:29+00:00 2026-06-15T04:24:29+00:00

I am having trouble making @Url.Action work with Area’s that have a non standard

  • 0

I am having trouble making @Url.Action work with Area’s that have a non standard route structure.

For instance if I register this route in my Dashboard area:

        context.MapRoute(
            "Dashboard_default",
            "Dashboard/{controller}/{action}/{id}",
            new { controller = "View", action = "Display", id = UrlParameter.Optional }
        );

and then in my layout view I call:

        @Url.Action("Select", "View", new { area = "Dashboard" })

I get a proper url: /Dashboard/View/Select

However, if I change the route to include an optional secondary id like this:

        context.MapRoute(
            "Dashboard_default",
            "Dashboard/{controller}/{action}/{id}/{secondaryid}",
            new { controller = "View", action = "Display", id = UrlParameter.Optional, secondaryid = UrlParameter.Optional }
        );

Then the same call to @Url.Action(…) doesn’t return any url. If I specify those optional parameters with real values like so:

        @Url.Action("Select", "View", new { area = "Dashboard", id = 1, secondaryid = 2 })

I do get a god return value of: /Dashboard/View/Select/1/2

The problem is that for some of my actions in this area don’t need the id or secondary id and I want the url to be generated without them. If i set them to (int?)null it still doesn’t work.

Am I doing something wrong? Shouldn’t Url.Action(…) return the URL without the id and secondaryid tokens if I dont specify them in the routeValues parameter?

  • 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-15T04:24:30+00:00Added an answer on June 15, 2026 at 4:24 am

    Having multiple optional parameters does funky things to your routes. Basically, the route engine cannot (has trouble) matching one or no optional parameters where there is a group of them. For more information, check out this blog post on the same issue.

    Since you don’t always need id or secondary id, just make a couple of routes to handle those cases.

    context.MapRoute(
                "Dashboard_IdAndSecondaryId",
                "Dashboard/{controller}/{action}/{id}/{secondaryid}",
                new { controller = "View", action = "Display"}
            );
    context.MapRoute(
                "Dashboard_default_WithSecondaryId",
                "Dashboard/{controller}/{action}/{secondaryid}",
                new { controller = "View", action = "Display"}
            );
    
    context.MapRoute(
                "Dashboard_default",
                "Dashboard/{controller}/{action}/{id}/",
                new { controller = "View", action = "Display", id = UrlParameter.Optional}
            );
    

    Now, when you send just an Id, just a secondaryId or both, you will have routes that will match. We can remove the optional parameter declarations in the first two routes, because in order to match that route, you would have to send the required parameters. Without sending the required parameters, you would want only the last route to match.

    The last route is your default route when only Id or none is sent in the action link. I believe that this order works as well, keeping in mind you want your routes to go from most specific to least specific given that they are processed in order.

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

Sidebar

Related Questions

I'm having trouble making python print out texts properly aligned. I have tried everything
I have just started making web pages and I'm having lots of trouble with
I'm having trouble making this work: $(function() { $(.button).click(function() { var newentry = $(input#entry).val();
i have used observed_field for arrays of data... but i am having trouble making
i am having trouble making this part of code to work, basically i want
I'm having trouble making php usort work. I fetch this from DB: Array (
I'm having trouble making folders that I create go where I want them to
So I'm having trouble making my placer face a planet. I have the angle
I am having trouble making a button that will check all the boxes (and
I have a website in aspx with c # and am having trouble making

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.