How can I return 500 error in JSON format in ASP.NET MVC?
问题 When ASP.NET MVC throws an exception, it returns a 500 error with response type text/html - which, of course, is invalid JSON. I want to respond to an Ajax request expecting JSON with an error I can receive and display to the user. Is it possible to return JSON with an HTTP status code of 500? When the problem is a missing parameter, the 500 error occurs before the controller is even called - so a controller solution might not work. For example, leaving a required parameter out in a call to