In my ASP.NET Core Razor Pages application, I sometimes send requests to the server via ajax.
In those cases, I want to return JsonResult either for success or for error.
But I can't find a way to change HTTP Status Code for JsonResult.
Here's my method:
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?
}
}
.StatusCodeon theJsonResultobject?