Model赋值返回json

 

 

 DataTable resultList = bll.GetResultListByCondition(bureauCode, deptCode, fileTitle);

        IList<GanBuTianChengTongZhiGuanLiResultViewModel> list = new List<GanBuTianChengTongZhiGuanLiResultViewModel>();

        //遍历行对象        

foreach (DataRow drEntry in resultList.Rows)        

{            

GanBuTianChengTongZhiGuanLiResultViewModel resultModel = new GanBuTianChengTongZhiGuanLiResultViewModel();

            PropertyInfo[] propertys = resultModel.GetType().GetProperties();                           

          foreach (PropertyInfo item in propertys)            

   {            

                            item.SetValue(resultModel, drEntry[item.Name].ToString(), null);     

        }

            list.Add(resultModel);    

     }

        jsonResult = new JavaScriptSerializer().Serialize(list);

        return jsonResult;

posted @ 2016-12-05 15:09  佳序  阅读(404)  评论(0编辑  收藏  举报