我完成了NerdDinner教程,现在我正在玩一些项目. 索引页面显示所有即将到来的晚餐: public ActionResult Index() { var dinners = dinnerRepository.FindUpComingDinners().ToList(); return View(dinners); } 在DinnerRepo
索引页面显示所有即将到来的晚餐:
public ActionResult Index() { var dinners = dinnerRepository.FindUpComingDinners().ToList(); return View(dinners); }
在DinnerRepository类中,我有方法FindAllDinners,我想在所有晚餐的索引方法编号上面添加,如下所示:
public ActionResult Index() { var dinners = dinnerRepository.FindUpComingDinners().ToList(); var numberOfAllDinners = dinnerRepository.FindAllDinners().Count(); return View(dinners, numberOfAllDinners); }
当然,这不起作用.因为我对OOP很陌生,所以我需要帮助.
谢谢,
岛
public class DinnerViewModel { public List<Dinner> Dinners { get; set; } public int NumberOfAllDinners { get; set; } } public ActionResult Index() { var dinners = dinnerRepository.FindUpComingDinners().ToList(); var numberOfAllDinners = dinnerRepository.FindAllDinners().Count(); return View(new DinnerViewModel { Dinners = dinners, NumberOfAllDinners = numberOfAllDinners } ); }