title: Binding Json data to a table in mvc 4
body: <p>I am working in an mvc 4 application..I want to bind a json data to a table in my application using jquery.I am able to convert a dataset (for which i get data from database) to json data using a method and get the json data.But i dont know how to bind it to a table using  jquery.Please tell me way to solve this problem..</p>
  
  <p><strong>JSon data</strong>:</p>
  
  <p>My json data is something like this..</p>
  
  <pre><code>[{"Location":"Chennai","Duration":"15","Sno":"1",
   "Date of Birth":"\/Date(-2209051800000)\/","Dateofjoin":"\/Date(-2209048200000)\/"}]
  </code></pre>
  
  <p><strong>Jquery</strong>:</p>
  
  <pre><code>$('#btnGoNew').click(function () {
          var url = '@Url.Content("~/Somecontroller/GetValue")'; 
          $.getJSON(url, { id: valz }, function (data) {
              //code to bind table                
          });
      });
  </code></pre>
  
  <p><strong>View</strong>:</p>
  
  <pre><code>         &lt;input type="button" class="MasterButton" id="btnGoNew"/&gt;
              &lt;table id="grd1"&gt;
               &lt;thead&gt;
                  &lt;tr&gt;
                     &lt;th&gt;Location&lt;/th&gt;
                     &lt;th&gt;Duration&lt;/th&gt;
                     &lt;th&gt;Sno&lt;/th&gt;
                     &lt;th&gt;Date of Birth&lt;/th&gt;
                     &lt;th&gt;Dateofjoin&lt;/th&gt;    
                  &lt;/tr&gt;
               &lt;/thead&gt;
               &lt;tbody&gt;
               &lt;tr&gt;
                &lt;td&gt;&lt;/td&gt;
               &lt;/tr&gt;
               &lt;/tbody&gt;
             &lt;/table&gt;
  </code></pre>
  
  <p><strong>Controller</strong>:</p>
  
  <pre><code>   public JsonResult GetValue(string id)
      {
          JsonResult json = new JsonResult();
          DataSet ds = LoadDoctordetailsNew(id); 
         /*LoadDoctordetailsNew is method where i get data from database and convert
            to dataset.It returns a dataset*/
          string returnData = GetJson(ds.Tables[0]);
          json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
          json.Data = returnData;            
          return json;
      }
  
      public static string GetJson(DataTable dt)
      {
          System.Web.Script.Serialization.JavaScriptSerializer serializer =
             new System.Web.Script.Serialization.JavaScriptSerializer();
          List&lt;Dictionary&lt;string, object&gt;&gt; rows =
             new List&lt;Dictionary&lt;string, object&gt;&gt;();
          Dictionary&lt;string, object&gt; row = null;
  
          foreach (DataRow dr in dt.Rows)
          {
              row = new Dictionary&lt;string, object&gt;();
              foreach (DataColumn col in dt.Columns)
              {
                  row.Add(col.ColumnName, dr[col]);
              }
              rows.Add(row);
          }
          return serializer.Serialize(rows);
      }
  </code></pre>