更新时间:2023-02-17 10:08:28
据我所见,ControllerBase
类内部有帮助方法.只需使用StatusCode
方法:
From what I can see there are helper methods inside the ControllerBase
class. Just use the StatusCode
method:
[HttpPost]
public IActionResult Post([FromBody] string something)
{
//...
try
{
DoSomething();
}
catch(Exception e)
{
LogException(e);
return StatusCode(500);
}
}
您还可以使用StatusCode(int statusCode, object value)
重载来协商内容.
You may also use the StatusCode(int statusCode, object value)
overload which also negotiates the content.