有没有办法可以将消息添加到BadRequest操作结果中,并使该消息对外部客户端(例如 Postman)可见?我正在使用 ASP.NET Core 3.1。
我的部分代码包含在下面。我想说的是问题是什么\xe2\x80\x94e.g.,id正文中发送的内容与从 URL 中获取的内容不同。现在,我正在使用Error我制作的一个对象,其中包含错误代码和消息。但当我发送请求时,这些在邮递员中不可见。
public ActionResult PutColour(int id, Colour colour)\n{\n if (id != colour.Id)\n {\n return BadRequest(new Error("IDNotTheSame","ID from URL is not the same as in the body."));\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n httprequest bad-request asp.net-core asp.net-core-webapi asp.net-core-3.1