找不到HTTP资源

时间:2017-08-04 09:29:38

标签: c# asp.net controller

我在我的api部门控制器上添加了这个,但是当我运行它时,网站上说它没有找到,我不熟悉c#任何帮助吗...

  [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
                });
            }

错误说

{
  "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."
}

这就是我要经过的 what i pass picture

这是我前端的代码

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

然后继续

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)));
    }
}

1 个答案:

答案 0 :(得分:1)

虽然DELETE请求中未明确禁止正文,但服务器经常忽略该正文。

尝试将操作更改为

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

使用参数构建您的网址,即添加?departmentCode=params.Code

另外值得检查this post发现错误,如果有邮件正文,则执行请求的库会自动将DELETE变为POST

您可以使用浏览器中的开发者工具轻松验证这一点(或将属性更改为[AcceptVerbs("Post")]至少用于测试