Ajax.ActionLink not POSTING

I am trying to switch to MVC action using POSTing, not GETting. (The action is DELETE, and I do not want it to be accessible via an external link.)

I am using the link in the grid generated

Ajax.ActionLink("Remove", "Delete", new { saID = Model.Said, id = e.id }, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you sure you want to delete this item?" }) 

What generates the following HTML:

 <a href="/Equipment/Delete/102424/229933" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, confirm: 'Are you sure you want to delete this item?', httpMethod: 'POST' });">Remove</a> 

My problem is that when I click on the link, I achieve the β€œDelete” action with GET, not POST, and the confirmation dialog is not executed. I searched for it several times for several hours and continued to wind around its axis. What am I doing wrong?

+6
ajax model-view-controller actionlink
source share
2 answers

You probably have another javascript error on your page that prevents javascript from running that handles AJAX POST. In this case, the link returns to the default (GET). The simplest is to use the IE8 or Firefox / Firebug developer tools (I prefer them) and see if you have any errors in the console when loading the page or when invoking your action. If you are using IE, you need to use Internet Options -> Advanced and uncheck Disable script debugging .

Fix the javascript bug and I think it will just start working.

+6
source share

I wanted to add this as a comment in accordance with the accepted answer, but for some reason there is no way to enter this as a comment, so adding this as an answer

In my case, I had to add "jquery.unobtrusive-ajax.min.js" to MicrosoftAjax.js and MicrosoftMvcAjax.js, and then an activation link started to trigger the ajax request. But it was GET, and I needed a post, so I added HttpMethod = "Post" to "AjaxOptions". That's all.

+5
source share

All Articles