title: MVC4 routing @Html.ActionLink and @Html.RouteLink producing wrong urls
body: <p>Maybe someone may help me to understand why <code>@Html.ActionLink</code> and  <code>@Html.RouteLink</code>  producing the wrong links in some cases.</p>
  <p>I have routes declared like that:</p>
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);
  
              routes.MapRoute(
                  &quot;Catalog&quot;, // Route name
                  &quot;Catalog/{a}/{b}/{c}/{d}/{e}&quot;, // URL with parameters
                  new { controller = &quot;Catalog&quot;, action = &quot;Index&quot;, a = UrlParameter.Optional, b = UrlParameter.Optional, c = UrlParameter.Optional, d = UrlParameter.Optional, e = UrlParameter.Optional } // Parameter defaults
              );
  
          routes.MapRoute(
              name: &quot;Default&quot;,
              url: &quot;{controller}/{action}/{id}&quot;,
              defaults: new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }
          );
      }
  </code></pre>
  <p>I have controller with my params:</p>
  <pre><code>public ActionResult Index(string a, string b, string c, string d, string e)
          {
          //Do stuff;
          }
  </code></pre>
  <p>I have list of cases with <code>@Html.RouteLink</code> and <code>@Html.ActionLink</code> on the view declared like that:</p>
  <pre><code>    @Html.ActionLink(&quot;ActionLink1&quot;,&quot;Index&quot;, new { a = &quot;a&quot; }, null)
      @Html.ActionLink(&quot;ActionLink2&quot;,&quot;Index&quot;, new { a = &quot;a&quot;, b = &quot;b&quot; }, null)
      @Html.ActionLink(&quot;ActionLink3&quot;,&quot;Index&quot;, new { a = &quot;a&quot;, b = &quot;b&quot;, c = &quot;c&quot; }, null)
      @Html.ActionLink(&quot;ActionLink4&quot;,&quot;Index&quot;, new { a = &quot;a&quot;, b = &quot;b&quot;, c = &quot;c&quot;, d = &quot;d&quot; }, null)
      @Html.ActionLink(&quot;ActionLink5&quot;,&quot;Index&quot;, new { a = &quot;a&quot;, b = &quot;b&quot;, c = &quot;c&quot;, d = &quot;d&quot;, e = &quot;e&quot; }, null)
      &lt;br/&gt;
      @Html.RouteLink(&quot;RouteLink1&quot;,&quot;Catalog&quot;, new { a = &quot;a&quot; })
      @Html.RouteLink(&quot;RouteLink2&quot;,&quot;Catalog&quot;, new { a = &quot;a&quot;, b = &quot;b&quot; })
      @Html.RouteLink(&quot;RouteLink3&quot;,&quot;Catalog&quot;, new { a = &quot;a&quot;, b = &quot;b&quot;, c = &quot;c&quot; })
      @Html.RouteLink(&quot;RouteLink4&quot;,&quot;Catalog&quot;, new { a = &quot;a&quot;, b = &quot;b&quot;, c = &quot;c&quot;, d = &quot;d&quot; })
      @Html.RouteLink(&quot;RouteLink5&quot;,&quot;Catalog&quot;, new { a = &quot;a&quot;, b = &quot;b&quot;, c = &quot;c&quot;, d = &quot;d&quot;, e = &quot;e&quot; 
  })
  </code></pre>
  <h2>The Results</h2>
  <p><strong>Current url</strong> <code>http://localhost:2288/Catalog</code></p>
  <p><code>ActionLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog?a=a</code></li>
  <li><strong>Expected Result:</strong> <code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <p><code>RouteLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <hr />
  <p><strong>Current url</strong> <code>http://localhost:2288/Catalog/a</code></p>
  <p><code>ActionLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog?a=a</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <hr />
  <p><strong>Current url</strong> <code>http://localhost:2288/Catalog/a/b</code></p>
  <p><code>ActionLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog/a/b</code></li>
  <li><strong>Expected Results:</strong><code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <p><code>RouteLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog/a/b</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <hr />
  <p><strong>Current url</strong> <code>http://localhost:2288/Catalog/a/b/c</code></p>
  <p><code>ActionLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog/a/b/c</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <p><code>RouteLink1</code></p>
  <ul>
  <li><strong>Actual Result:</strong> <code>http://localhost:2288/Catalog/a/b/c</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a</code></li>
  </ul>
  <p><code>ActionLink2</code></p>
  <ul>
  <li><strong>Actual Results:</strong> <code>http://localhost:2288/Catalog/a/b/c</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a/b</code></li>
  </ul>
  <p><code>RouteLink2</code></p>
  <ul>
  <li><strong>Actual Results:</strong> <code>http://localhost:2288/Catalog/a/b/c</code></li>
  <li><strong>Expected Results:</strong> <code>http://localhost:2288/Catalog/a/b</code></li>
  </ul>
  <p>And so on...</p>
  <hr />
  <p><strong>Current url</strong> <code>http://localhost:2288/Catalog/a/b/c/d</code></p>
  <p>ActionLink1, ActionLink2 and ActionLink3 as well as RouteLink1, RouteLink2, and RouteLink3 are all producing wrong urls.</p>
  <hr />
  <p><strong>Current url</strong> <code>http://localhost:2288/Catalog/a/b/c/d/e</code></p>
  <p><strong>All</strong> ActionLinks and RouteLinks (exept ActionLink5 and RouteLinks5) are producing wrong urls.</p>
  <hr />
  <p>I put a sample project here: <a href="http://www.mediafire.com/?gdbatoafgd0kf4w" rel="nofollow noreferrer">http://www.mediafire.com/?gdbatoafgd0kf4w</a></p>
  <p>May be someone can figure out why that is happening?</p>
  <p>That story started some days ago when i was trying to build Breadcrumbs with <code>MvcSiteMapProvider</code>, and i got same links produced by <code>MvcSiteMapProvider Breadcrumbs</code>.
  During my research i figure out that <code>MvcSiteMapProvider</code> not causing the problem the problem somewhere else. So i created default MVC4 project and it has such strange behavior by default.</p>
  <p><strong>UPDATE</strong></p>
  <p>It is looks like when you are using <code>@Html.ActionLink</code> and <code>@Html.RouteLink</code> helpers url generated based on current url..but still can't understand why when <code>Current url</code> <code>http://localhost:2288/Catalog</code> I am getting:</p>
  <p><code>http://localhost:2288/Catalog?a=a</code> instead of <code>http://localhost:2288/Catalog/a</code> in case of <code>ActionLink</code></p>
  <p>and <code>http://localhost:2288/Catalog</code> instead of <code>http://localhost:2288/Catalog/a</code> in case of <code>RouteLink</code></p>