DataTable转换为JsonResult

1、从数据库获取DataTable类型:

DataTable dt = DBConn.GetPageList(pageIndex, pageSize, "select * from erp_process" + pageSort, ref rowCount);

2、DataTable转换为var类型:

var query = from p in dt.AsEnumerable()
                            select new
                            {
                                ID = int.Parse(p["ID"].ToString()),
                                ProcessCode = p["ProcessCode"].ToString(),
                                ProcessName = p["ProcessName"].ToString(),
                                ProcessType = p["ProcessType"].ToString(),
                                ProcessMan = p["ProcessMan"].ToString(),
                                ProcessTypeName = TypeMapping(p["ProcessType"].ToString()),
                                ProcessManName = ManMapping(p["ProcessMan"].ToString())
                            };

3、返回JsonResult类型:

Json(new { rows = query, total = rowCount }, JsonRequestBehavior.AllowGet);

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。