【发布时间】:2022-01-24 05:37:36
【问题描述】:
在我的 ASP.NET Core Razor Pages 应用程序中,我有时会通过 ajax 向服务器发送请求。
在这些情况下,我想返回 JsonResult 表示成功或错误。
但我找不到更改 JsonResult 的 HTTP 状态代码的方法。
这是我的方法:
public IActionResult OnPostFileUpload()
{
try
{
// code to manage and save the file, this request is AJAX
return new JsonResult("done");
}
catch (Exception ex)
{
return new JsonResult(message); // how should I set it to be 500?
}
}
【问题讨论】:
-
在
JsonResult对象上设置.StatusCode?
标签: c# asp.net-core razor-pages