【发布时间】:2022-10-13 01:35:00
【问题描述】:
请,我正在尝试使用我的 C# 代码在 Blazor 组件中获取输入控件“txtCounter”的 ID。如何在 ASP.NET Core Blazor 组件中使用我的 C# 代码访问 Blazor 组件的 Id 属性值,即“txtCounter”。下面是我正在使用的代码。
谢谢,因为我期待收到您的回复。
【问题讨论】:
-
你需要这个id做什么?
请,我正在尝试使用我的 C# 代码在 Blazor 组件中获取输入控件“txtCounter”的 ID。如何在 ASP.NET Core Blazor 组件中使用我的 C# 代码访问 Blazor 组件的 Id 属性值,即“txtCounter”。下面是我正在使用的代码。
谢谢,因为我期待收到您的回复。
【问题讨论】:
你可以这样做:
<input type="text" id="@CounterInputId" value="@currentCount" />
@code {
private const string CounterInputId = "txtCounter";
private int currentCount = 0;
...
}
现在你有了 C# 代码中输入元素的 id。
【讨论】: