0
votes

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 ?

1
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
@BradChristie I'm calling it from the same controller. for example inside "home" controller and "about" actionabzarak

1 Answers

1
votes

surprisingly I put both Routes in route config and it solved the problem... But I think it's a misbehavior for Url.Action()