public ActionResult City(int pid = 0, int cid = 0) { int take = 10; int skip = take * pid; CityModel model = new CityModel(); model.PageID = pid; model.Current = pid + 1; ViewBag.pid = pid; IEnumerable <CityModel> Courses = new List <CityModel>(); CustomMethods.ValidateRoles("City"); var Citieslist = new CityBLL { }.GetAllCities(skip, take); if (cid != 0) { var sortedlist = new CityBLL { }.GetAllCities(skip, take, cid); double count = Convert.ToDouble(sortedlist.Count); var res = count / take; model.Pagecount = (int)Math.Ceiling(res); model.CityList = sortedlist.Select(x => new CityModel { CityId = x.CityId, CityName = x.CityName, StateId = x.StateId, IsActive = Convert.ToBoolean(x.IsActive) }).ToList(); } else { if (Citieslist != null) { double count = Convert.ToDouble(new CityBLL { }.GetPageCount()); var res = count / take; model.Pagecount = (int)Math.Ceiling(res); model.CityList = Citieslist.Select(x => new CityModel { CityId = x.CityId, CityName = x.CityName, StateId = x.StateId, IsActive = Convert.ToBoolean(x.IsActive) }).ToList(); } } return(View(model)); }
public static void BindCityList <T>(T model) { try { var cities = new CityBLL { }.GetAllCities(); if (cities != null) { model.GetType().GetProperty("CityList").SetValue(model, cities.Select(x => new SelectListItem { Value = x.CityId.ToString(), Text = x.CityName })); } } catch (Exception) { throw; } }