Bug reports Found a bug? Post it here please.
Version 7.x > Bug reports > MVC ActionLink resolves to wrong controller View modes: 
User avatar
Member
Member
ahaid-trainingpeaks - 9/18/2013 4:17:52 PM
   
MVC ActionLink resolves to wrong controller
I have a MVC View for displaying data on a page. I want to create a link for the user to delete a row of data. In the cshtml, when I use
@Html.ActionLink("Delete", "DeleteRow", "MyController")
the resulting link is
<a href="http://mysite/anothercontroller?action=DeleteRow&controller=MyController">Delete</a>

The problem is that 'anothercontoller' is rendered in the link when I want 'MyController' to be rendered. This happens on every Html.ActionLink I try to create. 'anothercontroller' is always there.

What is going on?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/3/2013 3:07:50 AM
   
RE:MVC ActionLink resolves to wrong controller
Hi,

How did you managed to get the "anothercontroller" to get there? Have you registered any custom routes or any other customizations?
Kentico is not doing any spesial handling for Html.ActionLink.

Best regards,
Juraj Ondrus

User avatar
Member
Member
ahaid-trainingpeaks - 10/3/2013 6:53:18 AM
   
RE:MVC ActionLink resolves to wrong controller
I solved this issue a few days after my original post.

'anothercontroller' was the first MVC page I created in CMS Desk. Even though I had a page for "MyController' also, the Html.ActionLink was only finding the first route. I went back through my default route registration which happens during Application_Start and this is the default route I was registering:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Login", action = "Index", id = UrlParameter.Optional }
);

Somehow this was colliding with the Kentico routes from the MVC pages I had created in CMS Desk. So, I decided to put my MVC controllers in a Route Area and I changed the default route registration to this:
routes.MapRoute(
"MyDefault", // Route name
"my/{controller}/{action}/{id}", // URL with parameters
new { controller = "Login", action = "Index", id = UrlParameter.Optional } //
);

Everything works fine now.