public async Task <ActionResult> Index(int page = 1) { int pageIndex = page < 1 ? 1 : page; var source = await this.GetYouBikeData(); source = source.AsQueryable().OrderBy(x => x.No); var model = new YouBikeViewModel { SearchParameter = new YouBikeSearchModel(), PageIndex = pageIndex, Snos = this.GetSelectList(await this.Snos, ""), Sareas = this.GetSelectList(await this.Sareas, ""), Snas = this.GetSelectList(await this.Snas, ""), YouBikes = source.ToPagedList(pageIndex, PageSize) }; return(View(model)); }
public async Task <ActionResult> Index(YouBikeViewModel model) { int pageIndex = model.PageIndex < 1 ? 1 : model.PageIndex; var source = await this.GetYouBikeData(); source = source.AsQueryable(); if (!string.IsNullOrWhiteSpace(model.SearchParameter.No)) { source = source.Where(x => x.No == model.SearchParameter.No); } if (!string.IsNullOrWhiteSpace(model.SearchParameter.Name)) { source = source.Where(x => x.Name == model.SearchParameter.Name); } if (!string.IsNullOrWhiteSpace(model.SearchParameter.Area)) { source = source.Where(x => x.Area == model.SearchParameter.Area); } source = source.OrderBy(x => x.No); var result = new YouBikeViewModel { SearchParameter = model.SearchParameter, PageIndex = pageIndex, Snos = this.GetSelectList( await this.Snos, model.SearchParameter.No), Sareas = this.GetSelectList( await this.Sareas, model.SearchParameter.Name), Snas = this.GetSelectList( await this.Snas, model.SearchParameter.Area), YouBikes = source.ToPagedList(pageIndex, PageSize) }; return(View(result)); }