UrlHelper.Action is not generating correct Route

I am generating URL inside my MVC4 Action Method.

redirectUrl = new UrlHelper(this.ControllerContext.RequestContext).Action(
                    "MyAction", "MyController", new { id = someVariable, id2= someVariable2});

Now the trouble is it's appending Id2 as Query parameter. I have a specific route defined in RouteConfig.cs that is like Controller/Action/Id/Id2

How can i force this to generate route specific URL

Upvotes: 1

Views: 1790

Answers (1)

Lee Bailey
Lee Bailey

Reputation: 3624

If you have a route set up in your RouteConfig.cs, you can call it by name using RouteUrl()

rectUrl = Url.RouteUrl("YourRouteName", new { id = someVariable, id2 = someVariable2 });

Upvotes: 4

Related Questions