I am using WebApi in a ASP.Net web application. I have a method in the controller called Delete and I want to access to this method by using jQuery's AJAX method.
Below is my code:
[Authorize]
public int Delete(int proposalId)
{
// logic here...
}
$.ajax({
url: "/Controller/Proposal/" + proposalId,
type: "Post",
contentType: "application/json",
success: function() {
bootbox.alert("Proposal deleted successfully.");
ReloadGrid();
},
error: function() {
}
});
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "controller/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
The problem is that when I am using POST it is executing another method which starts as Post. Can anyone please help me with this?
DELETEinstead ofPOSTin ajax ex.type: "Delete"