// GET: Subreddit public ActionResult Index() { using (var subredditContext = new RedditCloneContext()) { var subredditList = new SubredditListViewModel { Subreddits = subredditContext.Subreddits.Select(s => new SubredditViewModel { SubredditId = s.SubredditId, SubredditName = s.SubredditName, Posts = s.Posts }).ToList() }; return(View(subredditList)); } }
// GET: Subreddit public ActionResult Index() { using (var subredditContext = new RedditCloneContext()) { // Build a list of the subreddits currently in the database. var subredditList = new SubredditListViewModel { Subreddits = subredditContext.Subreddits.Select(s => new SubredditViewModel { SubredditId = s.SubredditId, SubredditName = s.SubredditName, Posts = s.Posts }).ToList() }; return(View(subredditList)); } }