在我的Blazor Server应用程序中,Razor页面之间的数据绑定无法正常工作。当数据更改时,在另一页中未刷新数据

发布于 2025-02-13 18:04:14 字数 960 浏览 0 评论 0原文

我有一个Blazor Server应用程序。页面的主要布局包括1)侧导航屏幕2)标题屏幕和3)页面中心的车身屏幕 在主屏幕(第1页)中,客户端必须从下拉式选择框中选择机器。我想要的非常简单:我希望所选的机器也立即显示在标题部分(Page2)。 我已经对以下数据进行了编程。但是,如果选择了机器,则不会在标题屏幕上显示。就在我手动重新加载页面时,我会在标题屏幕上看到正确的选择机器。我的数据绑定中缺少什么?

Page1(“页面”目录中的Body Razor页面)这是生成的数据

@page "/Selection" 
<select value="@selected_Machine" class="MAE" @onchange="func_MAE">
<option value="">-- Select Machine --</option>
<option value="">-- Machine-1 --</option>
<option value="">-- Machine-2 --</option>
<option value="">-- Machine-3 --</option>    
</select>

@code {
 public static string selected_Machine { get; set; }; 
 void func_MAE(Microsoft.AspNetCore.Components.ChangeEventArgs e)
    {          
      selected_Machine = e.Value.ToString();
    }
}

Page2(“共享”目录中的标题Razor Page),当数据更改中的数据更改时,应立即实现数据。

<p>Selected Machine: @Pages.Page1.selected_Machine</p>

I have a blazor server app. The main layout of the pages is consisting of 1) Side Navigation screen 2) Header screen and 3) the body screen in the center of the page
In the main screen (Page1) the client has to make a machine selection from a drop-down select box. What I want is very simple: I want that the selected machine is also shown immediatly in the header part(Page2).
I have programmed a data-binding like below. But if a machine is selected , it is not shown in the header screen. Just when I manual reload the page I see the correct selected machine in the header screen. What is missing in my data binding?

Page1 (Body razor page in the "Pages" directory) Here is the data generated

@page "/Selection" 
<select value="@selected_Machine" class="MAE" @onchange="func_MAE">
<option value="">-- Select Machine --</option>
<option value="">-- Machine-1 --</option>
<option value="">-- Machine-2 --</option>
<option value="">-- Machine-3 --</option>    
</select>

@code {
 public static string selected_Machine { get; set; }; 
 void func_MAE(Microsoft.AspNetCore.Components.ChangeEventArgs e)
    {          
      selected_Machine = e.Value.ToString();
    }
}

Page2 (Header razor page in the "Shared" directory) Here the data should be actualised immediatly when data changes in Page1.

<p>Selected Machine: @Pages.Page1.selected_Machine</p>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文