0

found interested case with routes in asp.net mvc.

Let's create clear empty solution with asp.net mvc 4 project.

Routes :

//more detail route
routes.MapRoute(
            name: "{lang}/category/{category}",
            url: "{lang}/category/{category}",                
            defaults: new { controller = "Home", action = "Index" }
        );
        //more general route
        routes.MapRoute(
            name: "{lang}",
            url: "{lang}",

            defaults: new { controller = "Home", action = "Index"  }
        );

in HomeController :

[HttpGet]
public ActionResult Index(string category = null)
{


   return View("~/Views/Home/index.cshtml");
}

Can anyone say WHY it returns "/en" for all Url.Action calls at urls except "/en/category/1"? I mean, if i go to, on example, /samplePage/blabla - it works as expected (generated url in html : /en), but when i go to "/en/category/1" - generated url in html changing to "en/category/1"!

  Url.Action("Index","Home", new {lang="en"}); //different behaviour for "/en" and  "/en/category/1" urls

Does current routeData from url should affect Url generate function?

UPDATE Same problem discussed here : UrlHelper.Action includes undesired additional parameters . Provided by @AndyNichols

Community
  • 1
  • 1
Nigrimmist
  • 10,289
  • 4
  • 52
  • 53
  • 1
    See [this question](http://stackoverflow.com/questions/20349681/urlhelper-action-includes-undesired-additional-parameters) where they had a similar problem. It seems that the existing route values are kept unless overwritten. – Andy Nichols Jun 10 '14 at 09:51
  • @Andy Nichols Maybe you should make this an answer so he can mark this question answered. – pixelmeow Jun 10 '14 at 14:14

0 Answers0