public ActionResult State(string SearchValue, string sortOrder, int pid = 0, int cid = 0) { int take = 10; int skip = take * pid; StateModel model = new StateModel(); model.PageID = pid; model.Current = pid + 1; IEnumerable <StateModel> Courses = new List <StateModel>(); CustomMethods.ValidateRoles("State"); var Citieslist = new StateBLL { }.GetAllState(skip, take); if (cid != 0) { var sortedlist = new StateBLL { }.GetAllState(skip, take, cid); double count = Convert.ToDouble(sortedlist.Count); var res = count / take; model.Pagecount = (int)Math.Ceiling(res); model.StateList = sortedlist.Select(x => new StateModel { CountryId = x.CountryId, CountryName = x.CountryName, StateId = x.StateId, StateName = x.StateName, IsActive = Convert.ToBoolean(x.IsActive) }).ToList(); } else { if (Citieslist != null) { double count = Convert.ToDouble(new StateBLL { }.GetPageCount()); var res = count / take; model.Pagecount = (int)Math.Ceiling(res); model.StateList = Citieslist.Select(x => new StateModel { CountryId = x.CountryId, CountryName = x.CountryName, StateId = x.StateId, StateName = x.StateName, IsActive = Convert.ToBoolean(x.IsActive) }).ToList(); } } return(View(model)); }
public static void BindStateList <T>(T model) { try { var cities = new StateBLL { }.GetAllState(); if (cities != null) { model.GetType().GetProperty("StateList").SetValue(model, cities.Select(x => new SelectListItem { Value = x.StateId.ToString(), Text = x.StateName })); } } catch (Exception) { throw; } }