how to return json error msg in asp.net web api?

后端 未结 5 1684
没有蜡笔的小新
没有蜡笔的小新 2021-02-03 21:14

I would like to return a json errormessage but at the moment in fiddler I cannot see this in the json panel:

string error = \"An error just happened\";
JsonResul         


        
5条回答
  •  心在旅途
    2021-02-03 22:16

    You can directly set the status code of the current HTTP response through Response property

    Response.StatusCod = (int)HttpStatusCode.BadRequest;
    return Json(HttpStatusCode.BadRequest);
    

提交回复
热议问题