Answer the question
In order to leave comments, you need to log in
What is causing the strange behavior of Url.Action in asp.net mvc 4?
Especially for the purity of the experiment, I created a new asp.net mvc 4 application.
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" }
);
[HttpGet]
public ActionResult Index(string category)
{
return View("~/Views/Home/index.cshtml");
}
Url.Action("Index","Home", new {lang="en"});
Answer the question
In order to leave comments, you need to log in
swap routes:
//more general route
routes.MapRoute(
name: "{lang}",
url: "{lang}",
defaults: new { controller = "Home", action = "Index" }
);
routes.MapRoute(
name: "{lang}/category/{category}",
url: "{lang}/category/{category}",
defaults: new { controller = "Home", action = "Index" }
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question