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
Post a Comment