Angular 6/C#/MVC Dynamically return JsonResult from controller in form of Json Array of Array

我怕爱的太早我们不能终老 提交于 2019-12-06 07:40:33

You should return the List<Dictionary<string, object>> instead of string. You don't need to Serialize the data it will be take care by JsonResult

public JsonResult GetValue()
{
    JsonResult json = new JsonResult();
    DataSet ds = GetMyData(); 
   /*LoadDoctordetailsNew is method where i get data from database and convert
      to dataset.It returns a dataset*/
    json.Data = GetJson(ds.Tables[0]);
    json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
    return json;
}

public static List<Dictionary<string, object>> GetJson(DataTable dt)
{
    List<Dictionary<string, object>> rows =
       new List<Dictionary<string, object>>();
    Dictionary<string, object> row = null;

    foreach (DataRow dr in dt.Rows)
    {
        row = new Dictionary<string, object>();
        foreach (DataColumn col in dt.Columns)
        {
            row.Add(col.ColumnName, dr[col]);
        }
        rows.Add(row);
    }
    return rows;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!