【问题标题】:AngularJS & WebAPI - get error message from the 400 errorAngularJS 和 Web API - 从 400 错误中获取错误消息
【发布时间】:2017-09-22 10:58:52
【问题描述】:

为什么我无法从以下代码中读取 AngularJS 中的错误消息

ModelState.AddModelError("field", "error");

return BadRequest(ModelState);

return BadRequest("error message");
return Content(System.Net.HttpStatusCode.BadRequest, new { field = "error"});

当我发现这个错误时,我得到的只是

    { 
        data: "Bad request", 
        status: 400, headers: ..... , 
        config: //POST method config, 
        statusText: "Bad Request" 
    }

【问题讨论】:

标签: javascript angularjs asp.net-web-api


【解决方案1】:

好的,我看到我有配置行:

<httpErrors errorMode="myMode" existingResponse="Replace">

应该是的

<httpErrors errorMode="myMode" existingResponse="PassThrough">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-07
    • 2018-12-20
    • 2019-11-27
    • 1970-01-01
    • 2019-05-31
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多