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

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); } }

你可能感兴趣的:(合并model并且呈现(asp.net MVC))