Guruprasad Rao Guruprasad Rao - 1 year ago 77
jQuery Question

type of ajax calls for [HttpDelete] Asp.Net MVC

What type of

calls will
MVC attribute listens to? Say I have below
decorated with

public JsonResult DeleteData(string id)
//deleting the data
return new Json{Data="Deleted", JsonRequestBehavior=JsonRequestBehavior.AllowGet};

Now I've tried to invoke these
but both of them couldn't trace this controller method. Its obvious that I can get this done through
attribute decoration, but since I am deleting a
and this way it should be better IMHO. How would we go invoking Controller methods decorated with
attribute through

Answer Source

MVC will handle mapping the appropriate HTTP Verbs to their corresponding attributes, so that it knows which actions to target (i.e. GET maps to [HttpGet], POST maps to [HttpPost], etc.)

So if you have a Controller Action that is decorated with the [HttpDelete] attribute, you'll need to make a DELETE request to actually hit it.

This can be handled quite easily when making a jQuery AJAX call, as you'll just need to explicitly use type: 'DELETE' as seen below :

    url: '{your-controller-action}',
    type: 'DELETE',
    success: function(result) {
          // Do something