简体   繁体   中英

Change or overwrite response badrequest message web api c#

How are you, people I need to change the response message of the return of BadRequest().

When I use the request like this, BadResquest("error: you can not pass these values")

I want to my api return something like this:

{"error: you can not pass these values"} 

but the endpoint retuned this :

{"Message":"error: you can not pass these values"}

I don't want the word "Message" in my response, is there any form to overwrite or change the response?.

You're free to create what ever response message you like. see http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/action-results

The BadRequest() helper method is just that. It's a workload reduction method that takes care of boilerplate stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM