Search code examples
ajaxasp.net-mvc-3routevalues

MVC3 .NET Ajax.ActionLink using POST option and URL generated shows id


I have Ajax.ActionLink that POSTS to a method on a controller and passes an Id. It definitely posts as I have decorated the method with: [HttpPost]. The url is displaying the Id value. Is this correct, as I would have thought POSTing would hide the Id from the url. I'm wondering if this is default functionality of MVC3 or whether I need to change my routevalues? Thanks


Solution

  • Decorating the controller method is not enough, and doesn't look to be the problem in this case.

    If the id is showing as part of the URL, the request is likely a GET rather than a POST.

    You can specify the request type in the Ajax.ActionLink. Make sure you indicate that it should be a POST.

    Do this using AJAX Options.