ASP.NET MVC 3 : How to force an ActionLink to do a HttpPost instead of an HttpGet?
asp.net-mvc, asp.net-mvc-3
Solution
`ActionLink` helper method will render an `anchor` tag, clicking on which is always a `GET` request. If you want to make it a `POST` request. You should override the default behviour using a little javacsript
@ActionLink("Delete","Delete","Item",new {@id=4},new { @class="postLink"})
Now some `jQuery` code
<script type="text/javascript">
$(function(){
$("a.postLink").click(function(e){
e.preventDefault();
$.post($(this).attr("href"),function(data){
// got the result in data variable. do whatever you want now
//may be reload the page
});
});
});
</script>
Make sure you have an `Action` method of `HttpPost` type to handle this request
[HttpPost]
public ActionResult Delete(int id)
{
// do something awesome here and return something
}
Problem
Is it possible to force an `@Html.ActionLink()` to do a `POST` instead of a `GET`? If so, how?