views:

175

answers:

2

I am having problems with Html.ActionLink when I have a route that takes one parameter. I have the following routers in global.asx:

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

When I use ActionLink passing two parameters, everything works ok. But when I try to create a link using the first route I end up with something like:

http://meusite.com/controller-name/%5Bparameter%5D,.html

EDIT:

Here is the action link that i`m having problems:

<span class="editar"><%=Html.ActionLink("Editar", "Edit", "Users", new { id = this.Model.login }, null)%></span>

This link is on another page that is used to manage user data.

A: 

Use:

Html.RouteLink("Link Title", new { controller = "Controller", Action= "Action" });
Martin
@Martin, but i have to pass ID of the user to get user information.
Cleiton
+1  A: 

First you should put your most generic route at the bottom.

Then, how about doing something like :

    routes.MapRoute(
        "materias",
        "{materias}/{action}/{id},{titulo_materia}.html",
        new { controller = "materias", action = "Index", id = "", titulo_materia = "" }  
    );

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

This way , the materias route only works for the materias controller. (not tested)

EDIT: htmm .. try using martin's example with a small addition :

Html.RouteLink("Link Title", new { controller = "Controller", Action= "Action",id = this.Model.login });
sirrocco
I tested it... But i`m getting same result. When i try create a link using actionlink with two paramters i get something like "http://meusite.com/controllerName/[first-paramters]?titulo_materia=foobar
Cleiton
yeah! I did it and it worked fine! thank you!
Cleiton