1
私はasp .net mvcに新しく、viewmodelでIPagedListページング機能を実装しようとしています。ページングと検索は正常なページでうまくいきますが、私はviewmodelと結合できません。ViewModelでIPagedListページング機能を使用し、asp .net mvcで結合する方法
私はこのアプローチを以下しています。ここではhttp://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
は私のViewModelクラスです:
ここpublic class SponserDisplayViewModel
{
public Sponser Sponser { get; set; }
public SponserDetail SponserDetail { get; set; }
public SponserType SponserType { get; set; }
} //--- Here All three are different classes.
私はコントローラーで試してみました何:
public ActionResult Index(string searchString, int? page, string btnSearch)
{
var viewModel = from s in db.Sponsers
join st in db.SponserTypes on s.SponserTypeId equals st.Id into st2
from st in st2.DefaultIfEmpty()
select new SponserDisplayViewModel { Sponser = s, SponserType = st };
if (btnSearch == "Reset")
{ searchString = string.Empty; }
if (!String.IsNullOrEmpty(searchString))
{
viewModel = from s in db.Sponsers
join st in db.SponserTypes on s.SponserTypeId equals st.Id into st2
from st in st2.DefaultIfEmpty()
where st.Name.Contains(searchString)
select new SponserDisplayViewModel { Sponser = s, SponserType = st };
}
int pageSize = 20;
int pageIndex = 1;
pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
//==================Getting error here
IPagedList<SponserDisplayViewModel> po = from s in db.Sponsers
join st in db.SponserTypes on s.SponserTypeId equals st.Id into st2
from st in st2.DefaultIfEmpty().OrderBy(a => a.DisplayOrder).ToPagedList(pageIndex, pageSize)
select new SponserDisplayViewModel { Sponser = s, SponserType = st };
return View(po);
}
を