as you know MVC default route is
context.MapRoute(
"Public_default",
"{controller}/{action}/{id}",
new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
)
and calling Url.Action("") was returning "/MyController"
After I changed the default route to :
context.MapRoute(
"Public_default",
"{controller}/{action}/{id}/{slug}",
new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
slug = UrlParameter.Optional
}
)
Now calling Url.Action("") is returning "/MyController/Index"
The problem is the "/index". it seems it's ignoring action = "Index" in route defaults.
I think it's happening because of adding {slug} to route.
note: when I call /MyController it's working like before. but Url.Action("") behavior is changed.
How can I solve this problem ?
Url.Action
(and other helpers) take the current context (RouteData) into equation when generating routes. I don't know from which page you're trying to generate a link from, but most likely it's taking those route values into equation. – Brad Christie