您的位置:首页 > 编程语言 > ASP

合并model并且呈现(asp.net MVC)

2009-09-27 09:56 453 查看
public ActionResult LoadRegionPerformance(TGProject.Models.WModels.TgsOutachiveCondition condition)
        {
            Account account = (Account)Session["Account"];
            var questions = SP.TgsAreaShow(int.Parse(account.AREAID.ToString()));
            
            List<TGProject.Models.WModels.TGSOUTACHIVEAREA> models=new List<TGProject.Models.WModels.TGSOUTACHIVEAREA>();
            TGSAREASHOW a;
            IEnumerator ie = (System.Collections.IEnumerator)questions.GetEnumerator();
            while (ie.MoveNext()) {
               a = (TGSAREASHOW)ie.Current;
               condition.AREAID = a.AREAID;
               List<TGProject.Models.WModels.TGSOUTACHIVEAREA> middlemodels = TGProject.Helpers.SP.TGSOutAchiveArea(condition);
               foreach (TGProject.Models.WModels.TGSOUTACHIVEAREA middlemodel in middlemodels)
                   models.Add(middlemodel);
            }
            return GetRegionPerformanceModelData(condition, models);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult GetRegionPerformanceModelData(TGProject.Models.WModels.TgsOutachiveCondition condition, List<TGProject.Models.WModels.TGSOUTACHIVEAREA> models)
        {
            int pageIndex = Convert.ToInt32(condition.Page) - 1;
            int pageSize = condition.Rows;
            int totalRecords = models.Count;
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
            AddField(models, totalPages, condition.Page, totalRecords);
            ViewData["RegionPerformance"] = models.Skip(pageIndex * pageSize).Take(pageSize).ToList();
            return View();
        }
        public static void AddField(List<TGProject.Models.WModels.TGSOUTACHIVEAREA> models, int totalPages, int page, int records)
        {
            foreach (TGProject.Models.WModels.TGSOUTACHIVEAREA model in models)
            {
                PropertyInfo pi1 = model.GetType().GetProperty("total");
                pi1.SetValue(model, totalPages, null);
                PropertyInfo pi2 = model.GetType().GetProperty("page");
                pi2.SetValue(model, page, null);
                PropertyInfo pi3 = model.GetType().GetProperty("records");
                pi3.SetValue(model, records, null);
            }
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: