How to report error to $.ajax without throwing exception in MVC controller?

前端 未结 7 563
天涯浪人
天涯浪人 2020-12-14 06:53

I have a controller, and a method as defined...

[HttpPost]
public ActionResult UpdateUser(UserInformation model){

   // Instead of throwing exception
   thr         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-14 07:20

    Based on what BigMike posted, this was what I did in my NON MVC/WEBAPI webproject.

    Response.ContentType = "application/json";
    Response.StatusCode = 400;
    Response.Write (ex.Message);
    

    For what it is worth (and thanks BigMike!) It worked perfectly.

提交回复
热议问题