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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:35:06+00:00 2026-05-25T16:35:06+00:00

In my layout page, the links to the main sections that make up my

  • 0

In my layout page, the links to the main sections that make up my site are rendered with a call like this:

@SiteSectionLink("index", "blog", "blog")

Where SiteSectionLink is a helper that looks like this:

@helper SiteSectionLink(string action, string controller, string display)
  {
  <li>
    <h1>
      <a class="site-section" href="@Url.Action(action, controller)">@display</a></h1>
  </li>
}

On the actual blog page, all links also refer to the “Index” action but also specify either a date parameter (such as “blog/4-2011” or “blog/2010”) that is used to filter the posts by a date period. In addition to that, there’s also an optional postID parameter that is used to refer to a specific post.

To accomplish that, I have the following routes:

routes.MapRoute(
 "Blog", 
 "blog/{date}/{postID}", 
  new 
  { 
    controller = "blog", 
    action = "index", 
    date = UrlParameter.Optional, 
    postID = UrlParameter.Optional 
  } 
);

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

Now, the problem is that when I have clicked a link that is something like “blog/11-2010” or “blog/11-2010/253” then the link in my layout page that refers to my blog in general now also refers to that same URL when I want it to just link to “blog/”, not “blog/11-2010”.

If I change the SiteSectionLink helper to explicitly pass in null for date and postID like this:

<a class="site-section" href="@Url.Action(action, controller, 
  new { date = (string)null, postID = (int?)null})">@display</a></h1>

The current route values are still used but now it looks like “blog?date=11-2010”.

I saw this similar question but the accepted answer doesn’t work for me, and I don’t use ActionLink in the first place and I suspect that ActionLink would use Url.Action under the hood.

  • 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-25T16:35:07+00:00Added an answer on May 25, 2026 at 4:35 pm

    While the issue you are experiencing is not quite the behavior detailed by Phil Haack in this blog post regarding a bug with MVC3 routing and a route with two optional parameters, I would suggest applying the fix described in Phil’s post.

    I also would suggest never creating a route with two optional parameters, and instead follow the pattern of breaking the desired routing into two separate routes.

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

Sidebar

Related Questions

I have a box on the site of my page layout that displays the
we have a Tiles layout page having Header, Menu, Body and Footer. In this
I'd like to get the name of my partial view in my layout page
I have a page layout that I use in my SharePoint solution when I
I have a section in my main layout like the following. I am starting
My main motivation for trying to do this is to get Javascript that is
I have a site layout that uses floats to achieve the desired columns/rows. On
I have something like @{ Html.RenderPartial(@~/Views/Management/_Main.cshtml); } Can I change this view without page
I have login/logout links in the main layout of my application, in the manner
I have a site that includes a Flash music player integrated into the layout.

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.