public ActionResult Index(int?page) { ApplicationDbContext _DB = new ApplicationDbContext(); List <PublicationViewModels.PartialPublication> result = new List <PublicationViewModels.PartialPublication>(); foreach (var publ in _DB.Publications) { string ImagePath; if (System.IO.File.Exists(publ.ImagePath)) { ImagePath = ConfigurationManager.AppSettings["PublicationAvatarsPath"] + publ.Id + ".png"; } else { ImagePath = ConfigurationManager.AppSettings["PublicationAvatarsPath"] + "default.png"; } List <ApplicationUser> subscribers = new List <ApplicationUser>(); result.Add(new PublicationViewModels.PartialPublication() { PublicationId = publ.Id, PublicationName = publ.Name, DateOfPublication = publ.DateTimeOfPublication.ToString(), ImagePath = ImagePath.Remove(0, 1), PublicationText = publ.Text, Subscribers = publ.Subscriptions.ToList(), Creator = (publ.Author.FirstName + " " + publ.Author.SurName), DateOfMeet = publ.DateOfMeeting.ToString(@"MM\/dd\/yyyy HH:mm:ss") //Subscribers = publ.Subscriptions.ToList() }); } int pagesize = 3; int pagenumber = (page ?? 1); return(View(result.ToPagedList(pagenumber, pagesize))); }