c# - More efficient way to return errors in .NET Web Api 2 iHttpActionResult object? -


i want return http error code along json object in service. cannot find straightforward way this.

right way i'm doing it:

if (!modelstate.isvalid) {     return responsemessage(request.createresponse(httpstatuscode.badrequest, new badrequesterror(modelstate))); } 

basically create httpresponse, object want return, , "convert it" ihttpactionresult instance.

is right? or should doing way?

if sure badrequest correct error message, can use badrequest(string error) method, seen here. send json, first parse string , pass parameter.

this done controller class, , available superclasses of apicontroller type. also, please note there methods other error types in apicontroller class.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -