Hi @mc,
You can return an object in Razor Pages, but it may not work as what you done. Razor Pages are designed to return IActionResult
objects for HTTP responses. If you return a plain object, it won't automatically serialize to JSON or render properly.
To properly handle this, you should return a JsonResult
to send JSON data, especially for AJAX requests.
For Example, modify your code like below:
public async Task<IActionResult> OnPostDeleteAsync()
{
return new JsonResult(new MySuccessMessage());
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena