【问题标题】:How to Get the Id Attribute of an Input Control in a Blazor Component如何在 Blazor 组件中获取输入控件的 Id 属性
【发布时间】:2022-10-13 01:35:00
【问题描述】:

请,我正在尝试使用我的 C# 代码在 Blazor 组件中获取输入控件“txtCounter”的 ID。如何在 ASP.NET Core Blazor 组件中使用我的 C# 代码访问 Blazor 组件的 Id 属性值,即“txtCounter”。下面是我正在使用的代码。

image of my code

谢谢,因为我期待收到您的回复。

【问题讨论】:

  • 你需要这个id做什么?

标签: c# blazor


【解决方案1】:

你可以这样做:

<input type="text" id="@CounterInputId" value="@currentCount" />

@code {
    private const string CounterInputId = "txtCounter";

    private int currentCount = 0;
    ...
}

现在你有了 C# 代码中输入元素的 id。

【讨论】:

    猜你喜欢
    • 2021-12-11
    • 2021-05-27
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多