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