一个 Razor 页面中的多个 Razor 组件
问题如下。有一个 Razor Page 项目(Blazor 的混合体)。其中一个页面在 ServerPrerendered 模式下使用两个 Razor 组件。它们每个的初始化都需要从数据库加载数据。当页面上仅涉及一个组件时,不会有任何问题 - 一切都按预期工作,包括交互性。但如果你同时使用两个组件,就会发生一些难以理解的事情——只有其中一个组件被正确初始化,而且每次都不同。我不知道该看哪里,因为在带有断点的调试模式下,一切都正常。请告诉我,可能有什么问题?
初始化其中一个组件
protected override async Task OnInitializedAsync()
{
var postRating = await koooirDbContext.PostRatings
.FirstOrDefaultAsync(f => f.PostId == PostId);
if (postRating != null)
{
current = new CurrentRating
{
Rating = postRating.Rating,
Votes = postRating.Votes
};
}
dataIsLoaded = true;
}
The problem is the following. There is a Razor Page project (a hybrid of Blazor). One of the pages uses two Razor Components in ServerPrerendered mode. Initialization of each of them requires loading data from the database. When only one component on the page is involved, there are no problems - everything works as expected, including interactivity. But if you use two components at the same time, something incomprehensible happens - only one of the components is initialized correctly, each time it is different. I can't figure out where to look, because in debugging mode with breakpoints everything works out correctly. Tell me, please, what could be the catch?
Initializing one of the components
protected override async Task OnInitializedAsync()
{
var postRating = await koooirDbContext.PostRatings
.FirstOrDefaultAsync(f => f.PostId == PostId);
if (postRating != null)
{
current = new CurrentRating
{
Rating = postRating.Rating,
Votes = postRating.Votes
};
}
dataIsLoaded = true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题被删除。问题在于共享 DbContext。 解决方案。
The question is removed. The problem was sharing DbContext. Solution.