Vs.js代码-这里是axios.delete和挂载的部分:
mounted() {
this.getCreated();
},
deleteRequest(id) {
axios.delete("http://localhost:32961/api/request/delete"+id)
.then(() => {
this.getCreated()
})
.catch((err) => console.error(err));
},
C#代码-这是后端部分(控制器):
[Route("delete/{id}")]
[HttpDelete]
public IActionResult Delete([FromBody] Request request)
{
_db_Context.Requests
.FirstOrDefault(a => a.RequestId == request.RequestId);
_db_Context.Requests.Remove(request);
_db_Context.SaveChanges();
return Ok(request);
}
我想我在vue.js axios.delete部分犯了一个错误。我得到了错误代码405。我该怎么修复它呢?
2条答案
按热度按时间gcuhipw91#
你该换衣服了
到
并在C#API代码中执行此操作:
或者,如果您使用id的查询字符串调用Delete API,则应在api中设置
FromUri
。查看此link
cx6n0qe32#
Abbas Aryanpour指出代码中缺少
/
是正确的,但是我认为错误消息应该是404,而不是405。I think this should be related to your asp.net core back-end code not setting cross-domain, or you have set cross-domain, but did not notice the execution order of middleware, so it may cause cross-domain not to take effect.
1.解决连接错误
2.跨源资源共享