Ends in:
7 DAYS
11 HRS
37 MIN
31 SEC
Ends in:
7 D
11 H
37 M
31 S
Open Closed

How to return error message in a Razor page's OnPostAsync Method #4104


User avatar
0
coop1 created

Hi there,

I have a Razor form that is creating a new entry in the database with a Name field that must be unique. I am performing server-side validation in the OnPostAsync method and if the submitted Name entry already exists in the database, the method returns an error. The returned error object is a Microsoft.AspNetCore.Mvc.ContentResult with the StatusCode set to 400 and the Content set to an error message stating the submitted name already exists, this causes the ABP "An error has occurred!" modal to pop up but the message is not displayed, and instead the modal just says "Error detail not sent by server.". How do I properly return an error from the server side so that my custom error message can be displayed?

Thank you!


1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    If an exception implements the IUserFriendlyException interface, then ABP does not change it's Message and Details properties and directly send it to the client.

    You can use UserFriendlyException for this. For more information, I recommend you look here.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06