Search code examples
asp.net-mvc-4actionlink

ActionLink not outputting correct path


Could you please help me figure out what is wrong with below razor syntax. I am trying to output an anchor tag with a link to MVC action.

Razor Syntax:

@Html.ActionLink("Back to Reports List", "Index", "Reports")

Output in the browser:

<a href="/">Back to Reports List</a>

and not:

<a href="/Reports/Index">Back to Reports List</a>

Any idea?


Solution

  • Please show your route config. The url generated based on that. It is possible that your route config start with:

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