[英]ASP.NET Core MVC - Model properties passed to view showing null in Razor
I'm passing a view-model to a partial view and by stepping through the code I can tell that the expected data is there:我将视图模型传递给局部视图,并通过单步执行代码,我可以知道预期的数据在那里:
eg the BatteryLevelTooltip
property例如BatteryLevelTooltip
属性
However, stepping over this, the BatteryLevelTooltip
then becomes null and data isn't rendered in the view:但是,越过这个, BatteryLevelTooltip
就会变成 null 并且数据不会在视图中呈现:
I cannot, for the life of me work out why.我不能,因为我一生都在弄清楚为什么。 I'm passing other data in the same way and that's being rendered fine further down the view.我以相同的方式传递其他数据,并且在视图的下方呈现得很好。
It turned out that for some reason I was setting this property in the getter of another property.事实证明,出于某种原因,我将此属性设置在另一个属性的 getter 中。 This was causing it to return null when it was accessed directly.这导致它在直接访问时返回 null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.