【问题标题】:Http Delete not found未找到 Http 删除
【发布时间】:2018-01-14 07:16:40
【问题描述】:

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

 [HttpDelete]
         public async Task<IHttpActionResult> Remove([FromBody] Department tObj, [FromUri]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/Remove'.",
  "MessageDetail": "No action was found on the controller 'Department' that matches the request."
}

请求负载

{Key: 18, Users: null, Projects: null, Status: null, Code: "ppp", Name: "lll", IsActive: true,…}
Code:"ppp"
IsActive:true
Key:18
Name:"lll"
Projects:null
State:2
Status:null
StatusMessage:null
Users:null

这是前端(REACTJS)

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

然后它继续到这个ajax

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

我不确定为什么它没有读取控制器,因为除了 remove 之外的其他控制器正在工作..

【问题讨论】:

    标签: c# asp.net api reactjs


    【解决方案1】:

    如下改变你的方法;

            [HttpDelete("{tagAsDeletedOnly?}")]       
            public async Task<IHttpActionResult> Remove([FromBody] Department tObj, [FromRoute]bool? tagAsDeleteOnly) // use FromRoute
            {
                _bll.Delete(tObj, tagAsDeleteOnly ?? true);
    
                var result = await _bll.Save();
    
                return Ok(new WebResult
                {
                    Data = tObj,
                    Total = (int)result,
                    Result = result > 0
                });
            }
    

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 2021-10-05
      • 1970-01-01
      • 2016-09-07
      • 1970-01-01
      • 2014-04-14
      相关资源
      最近更新 更多