2

Is it possible to Invoke a HttpPost Action method from @Html.ActionLink ?

[HttpPost]
public ActionResult Delete()
{    
  // delete 
}

@Html.ActionLink("Delete","Delete","Cart") will render an anchor tag which is a get request.

I have a list of products i am showing in the shopping cart and i want to add a delete button.

Happy
  • 1,767
  • 6
  • 22
  • 26
  • So make delete a get. Why does it need to be a post? – mccow002 Apr 12 '12 at 20:46
  • 2
    @mccow002, Generally not a good idea for actions that modify data (such as deleting items) to be GETs. See: http://stackoverflow.com/questions/786070/why-should-you-delete-using-an-http-post-or-delete-rather-than-get – Brandon Apr 12 '12 at 20:50
  • @mccow002: Get for delete ? Really ? This is something worth to read http://stackoverflow.com/a/679042/40521 – Happy Apr 12 '12 at 20:51
  • 1
    fair enough. Any place I've ever implemented a delete as a get has been behind security, so I didn't have to worry about a google bot or something. But yea, didn't realize all that could happen with the delete as a get on an open site. Try to answer a question, you learn something yourself. Thanks – mccow002 Apr 12 '12 at 20:56

1 Answers1

3

add a javascript listener on the click event of that actionLink and in the callback function of the listener just do s POST to your action.

Baz1nga
  • 15,485
  • 3
  • 35
  • 61