Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url.Action(controller, action) not routing as expected

In my ASP.NET MVC 3, I am using this code

<a [email protected]("myController", "myaction")>

But when I click on it, it does't go to my action. Instead, in the URL I see this

http://localhost:1402/?Length=2

Am I missing something?

Thanks.

Edit :

Here are my routes :

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }
like image 484
kbaccouche Avatar asked Dec 04 '22 17:12

kbaccouche


2 Answers

the first argument is interpretted as the Action

@url.Action("myaction","myController")
like image 189
Rafay Avatar answered Dec 30 '22 23:12

Rafay


The signature of Url.Action is:

Url.Action(string actionName, string controllerName)

According to your code, the order of your parameters are incorrect, you should try:

@Url.Action("myAction", "myController")

Also remember that to remove the "Controller" part of the controller, for exemple, if I have a CustomerController with a Index action that would be like that:

@Url.Action("Index", "Customer")
like image 44
Charles Ouellet Avatar answered Dec 30 '22 21:12

Charles Ouellet