We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to resolve the "404 error" that occurs when delete API is called in WebAPI application?

Problem

While triggering the deleteAPI in the WebApi sample, the following error is obtained and thus the deleteApi is not called.

Server Error in '/' Application.

The resource cannot be found.

Description

HTTP 404. The resource you are looking for, or one of its dependencies, could have been removed, had its name changed, or is temporarily unavailable. Review the following URL and make sure that it is spelled correctly.

Requested URL: /api/Orders/10248

Reason

When the POST and PUT actions are triggered, no additional parameters are appended to the Route link, that is api/Orders, and so these events are triggered. Refer to the following screenshot.

 

http://www.syncfusion.com/downloads/support/directtrac/135010/2065888990_b5f00299.BMP

Figure 1: POST and PUT actions triggered

When the DELETE action is triggered, the primary key value is also appended to the Route link, that is, api/Orders/10248. Refer to the following screenshot.

 

http://www.syncfusion.com/downloads/support/directtrac/135010/2067375557_c9a8c592.BMP

Figure 2: DELETE action triggered

Solution

Since the Route in the WebApiConfig file does not include the id parameter, the 404 error is thrown. Refer to the following screenshot.

Incorrect Example

So changing the Route link in the WebApiConfig resolves this error.

Correct Example

Result:

After changing the route in the WebApiConfig.cs file, the deleteApi is called as shown in the following screenshot.

http://www.syncfusion.com/downloads/support/directtrac/135010/2067331759_ca771112.BMP

Figure 3: Result

Article ID: Published Date: Last Revised Date: Platform: Control:
4119 02/20/2015 02/20/2015 ASP.NET MVC Grid
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.