I am getting a run time error of "Object reference not set to an instance of an object." for posts in the following code, would anyone be able to help me fix?
private HomeIndexModel BuildHomeIndexModel()
{
var LatestPosts = _postService.GetLatestPosts(10);
var posts = LatestPosts.Select(post => new PostListingModel
{
Id = post.Id,
Title = post.Title,
AuthorId = post.User.Id,
AuthorName = post.User.UserName,
AuthorRating = post.User.Rating,
DatePosted = post.Created,
RepliesCount = post.Replies.Count(),
Forum = GetForumListingForPost(post)
});
return new HomeIndexModel()
{
LatestPosts = posts
};
}
GetLatestPosts() from the post service is as follows
public IEnumerable<Post> GetLatestPosts(int count)
{
var allPosts = GetAll().OrderByDescending(post => post.Created);
return allPosts.Take(count);
}