Search code examples
asp.net-mvcasp.net-mvc-4actionlink

MVC ActionLink Odd Routing Behavior -- Adds link to the end of the url after hash


I'm working on an MVC .Net 4.5 web app and my links are misbehaving.

Here's my starting URL: http://localhost:58982/Game/Index

Here's the RAZR code and resulting html:

@Html.ActionLink("Occasion", "Index", "Occasion")
<a href="/Occasion">Occasion</a>

But when I click the link my URL looks like this: http://localhost:58982/Game/Index#/Occasion

When a link takes me to the same page the browser does not refresh and the controller is not called.

Is there a setting I need to change somewhere?


Solution

  • if your action takes no parameter you don't need to pass parameter:

    @Html.ActionLink("Occasion", "Index", "Occasion")
    

    but if your action takes parameter:

    public ActionResult Index(int ID)
    {
    //
    }
    

    it would be something like this:

     @Html.ActionLink("Occasion", "Index", "Occasion", new {Id=Model.Id},null)