C# 虚拟方法引用的类返回空的ASP.Net核心MVC

C# 虚拟方法引用的类返回空的ASP.Net核心MVC,c#,reference,virtual,nullreferenceexception,C#,Reference,Virtual,Nullreferenceexception,我带着问题来 为什么我的类返回空值 正如您在上所看到的,类返回null,但其中的字段是空的 这是一个Post模型,我将虚拟方法放在类Category中,类 为什么会这样 我查了所有的参考资料,都很好。 这可能是由Windows Update或IIS/VisualStudio引起的 请帮忙 后期模型 使用系统; 使用System.Collections.Generic; 命名空间收集器_forum.Data.Models { 公营职位 { 公共int Id{get;set;} 公共字符串标题{ge

我带着问题来

为什么我的类返回空值

正如您在上所看到的,类返回null,但其中的字段是空的

这是一个Post模型,我将虚拟方法放在类Category中,类

为什么会这样

我查了所有的参考资料,都很好。 这可能是由Windows Update或IIS/VisualStudio引起的

请帮忙

后期模型

使用系统;
使用System.Collections.Generic;
命名空间收集器_forum.Data.Models
{
公营职位
{
公共int Id{get;set;}
公共字符串标题{get;set;}
公共字符串内容{get;set;}
已创建公共日期时间{get;set;}
公共虚拟应用程序用户{get;set;}
公共虚拟类别{get;set;}
公共虚拟IEnumerable回复{get;set;}
}
}
类别模型

使用系统;
使用System.Collections.Generic;
命名空间收集器_forum.Data.Models
{
公共类类别
{
公共int Id{get;set;}
公共字符串标题{get;set;}
公共字符串说明{get;set;}
已创建公共日期时间{get;set;}
公共字符串ImageUrl{get;set;}
公共虚拟IEnumerable Posts{get;set;}
}
}
索引从HomeController构建HomeIndex方法:

public IActionResult Index()
{
var model=BuildHomeIndexModel();
返回视图(模型);
}
公共HomeIndexModel BuildHomeIndexModel()
{
var latestPosts=_postService.GetLatestPosts(10);
var posts=latestPosts.Select(post=>newpostlistingmodel
{
Id=post.Id,
Title=post.Title,
AuthorId=post.User.Id,
AuthorName=post.User.UserName,
AuthorRating=post.User.Rating,
DatePosted=post.Created.ToString(),
RepliesCount=post.Replies.Count(),
类别=GetCategoryListingForPost(post)
});
返回新的HomeIndexModel
{
最新帖子=帖子,
SearchQuery=“”
};
}
PostListingModel如果需要:

使用collector\u forum.Models.Category;
命名空间收集器_forum.Models.Post
{
公共类PostListingModel
{
公共CategoryListingModel类别{get;set;}
公共int Id{get;set;}
公共字符串标题{get;set;}
公共字符串内容{get;set;}
公共字符串AuthorName{get;set;}
公共int编写{get;set;}
公共字符串AuthorId{get;set;}
公共字符串DatePosted{get;set;}
public int CategoryId{get;set;}
公共字符串CategoryName{get;set;}
公共字符串CategoryImageUrl{get;set;}
public int replesscount{get;set;}
}
}
类别分类模型如果需要:

使用collector\u forum.Models.Post;
使用System.Collections.Generic;
命名空间收集器_forum.Models.Category
{
公共类分类模型
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公共字符串ImageUrl{get;set;}
public int NumberOfPosts{get;set;}
public int NumberOfUsers{get;set;}
公共bool HasRecentPost{get;set;}
公共PostListingModel最新版本{get;set;}
}
}

不要发布代码的图像,给我们实际的代码,以便我们可以根据需要复制/粘贴。问题是什么。你有什么错误吗?当然,给你-