title: JSON serialization in asp.net MVC
body: <p>In my sample asp.net MVC application , when ever user makes an AJAX call from browser , I would like to return data in JSON format mentioned below.</p>
  
  <pre><code>{
      "success":true,  // true or false
      "errorMessage":"", // errorMessage if there is any error
      "data": { } //this value will depend on the action method called
  }
  </code></pre>
  
  <p>To return response in this format , I create an anonymous type in all action methods and then serialize it to JSON.  </p>
  
  <pre><code>public ActionResult GetAuthors()
  {
      List&lt;BookStoreAdmin.ViewModels.Author&gt; authors = BookStoreAdmin.BAL.Author.GetAuthors();
      var response = new { success = true, errors = "", data = authors };
  
      return Json(response, JsonRequestBehavior.AllowGet);
  
      // return Json(authors, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>Now , my question is there any better way or correct way to do this , instead of creating anonymous type in all action methods ?</p>