LAGIM
LAGIM

Reputation: 9

No HTTP resource was found

I added this on my api department conrtoller however when I run it the website says that it is not found, I am not familiar with c# any help with do..

  [HttpDelete]
            [AcceptVerbs("Delete")]
            [ResponseType(typeof(Department))]
            public override async Task<IHttpActionResult> Delete(Department tObj, bool? tagAsDeleteOnly)
            {
                _bll.Delete(tObj, tagAsDeleteOnly ?? true);

                var result = await _bll.Save();

                return Ok(new WebResult
                {
                    Data = tObj,
                    Total = (int)result,
                    Result = result > 0
                });
            }

the error says

{
  "Message": "No HTTP resource was found that matches the request URI 'http://localhost:8933/api/Department/Delete'.",
  "MessageDetail": "No action was found on the controller 'Department' that matches the request."
}

this is what I am passing what i pass picture

this is my code on my front end

delete(form) {
        debugger
        form.State = 2;
        let id = form.Key;
        //delete form.Key;
        this.props.deleter('department/Delete', form);
}   

and then it proceed to

export const deleter = (url, params) => {
    return(dispatch, getState, api) => {
        api += 'api/';
        return fetch(`${api}${url}`, {
            method: 'DELETE',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(params)
        })
        .then(response => response.json())
        .then(result => dispatch(departmentResult(result, types.DELETER)));
    }
}

Upvotes: 0

Views: 117

Answers (1)

ste-fu
ste-fu

Reputation: 7434

Whilst a body is not explicitly forbidden in a DELETE request, it is frequently ignored by the server.

Try changing your Action to

public override async Task<IHttpActionResult> Delete(string departmentCode, bool? tagAsDeleteOnly)

and construct your url using parameters ie add ?departmentCode=params.Code

Also worth checking this post found an error where the library performing the request automatically turned a DELETE into a POST if there was a message body present.

You can easily verify this by using the Developer Tools in your browser (or changing the attribute to [AcceptVerbs("Post")] at least for testing

Upvotes: 1

Related Questions