System.NullReferenceException创建一个详细信息查看站点模型,该模型来自区域模型
详细信息。cshtml(用于站点)
这是导致问题的代码的一部分,
<b>Region: </b>
<a asp-controller="Regions" asp-action="Details" asp-route-id="@Model.RegionID">
@Model.Region.Name
</a>
</p>
我的网站模型具有一个名为regionID的字段,该字段代表该站点所在的区域,当我试图检索区域名称以在详细信息中显示该区域以显示它网站的视图我正在获取系统。NullReferenceException
Details.cshtml (For Site)
This is the part of the code causing problem
<b>Region: </b>
<a asp-controller="Regions" asp-action="Details" asp-route-id="@Model.RegionID">
@Model.Region.Name
</a>
</p>
my site model has a field called RegionID which represents the region in which the site is located and when i am trying to retrieve the Region name to display it in the details view of the site i am getting the System.NullReferenceException
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在详细信息中修复EF代码
you have to fix you ef code in Details action
您可以尝试为
model.gregion
设置默认值:You can try to set a default value for
Model.Region
: