我有一个角度/ MVC应用程序组合。用户进入可以修改记录单击按钮调用服务,该服务执行帖子以更新数据库中的记录。它命中控制器(我在构造函数上有断点),但不是方法,而是抛出405.
按钮单击处理程序:
$scope.submit = function() {
console.log($scope.request);
requests.updateRequest($scope.request).then(onUpdate, onError);
}
请求资源:
var updateRequest = function (request) {
return $http.post("/api/request/update/", request).then(function (response) {
return response.data;
});
};
路由在单独的文件中配置:
config.Routes.MapHttpRoute("UpdateRequest", "api/request/update/", new { controller = "Requests", action = "UpdateRequest"});
RequestController构造函数被命中,但我无法弄清楚为什么没有命中以下端点。
控制器方法:
[HttpPost]
public HttpResponseMessage UpdateRequest([FromBody] IRequest request)
{
try
{
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content =
new ObjectContent(
typeof(int),
request.Id,
new JsonMediaTypeFormatter())
};
return response;
}
catch (Exception ex)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}
有什么想法吗?
答案 0 :(得分:0)