Search code examples
asp.net-mvcrazor

ASP.NET MVC 5 Actionlink ignores actionname


This:

@Html.ActionLink(linkText: Txt.Get("rsTerugNaarOverzicht"),
                 actionName: "Index",
                 controllerName: "OfferteOverzicht", 
                 routeValues: new { is10Days = true, maand = Model.OverzichtMaand, jaar = Model.OverzichtJaar }, 
                 htmlAttributes: new { @class = "wijzigen" })

is rendered as:

<a class="wijzigen" href="/OfferteOverzicht?is10Days=True&maand=3&jaar=2021">Terug naar overzicht</a>

I was expecting this:

<a class="wijzigen" href="/OfferteOverzicht/Index?is10Days=True&maand=3&jaar=2021">Terug naar overzicht</a>

What am I doing wrong here?


Solution

  • Resolved it. It was caused by an entry in the routeconfig:

       routes.MapRoute( 
        name: "Root",
        url: "{action}",
        defaults: new { controller = "Home", action = "Index" }
       );
    
       routes.MapRoute(
           name: "Default",
           url: "{controller}/{action}/{id}",
           defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
       );
    

    I needed to remove the first one.

    Now, eventhough not visible in the link, the action is called and executed.