title: .Net MVC4 - How to return exception in json format?
body: <p>I have a MVC4 application where I call a controller action from javascript using jQuery. When an exception occurs in the controller the returned response text is in HTML format. I want it to be in JSON format. How can this be achieved?</p>
  
  <p>I thought some JSON formatter should do the magic on its own...</p>
  
  <p>JavaScript</p>
  
  <pre><code>// Call server to load web service methods
  $.get("/Pws/LoadService/", data, function (result) {
      // Do stuff here
  }, "json")
  .error(function (error) { alert("error: " + JSON.stringify(error)) });
  </code></pre>
  
  <p>.Net Controller Action</p>
  
  <pre><code>[HttpGet]
  public JsonResult LoadService(string serviceEndpoint)
  {
      // do stuff that throws exception
  
      return Json(serviceModel, JsonRequestBehavior.AllowGet);            
  }
  </code></pre>