![](/img/trans.png)
[英]Need HTTP Status (200/500/etc) Code from WebBrowser Control
[英]How to return JsonResult with HTTP Status Code 500 from Razor Page?
在我的 ASP.NET Core Razor Pages 應用程序中,我有時會通過 ajax 向服務器發送請求。
在這些情況下,我想為成功或錯誤返回JsonResult
。
但是我找不到更改 JsonResult 的JsonResult
狀態代碼的方法。
這是我的方法:
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?
}
}
您可以將 StatusCode 分配給JsonResult
,如下所示:
using System.Net;
return new JsonResult(message)
{
StatusCode = (int)HttpStatusCode.InternalServerError
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.