Dynamic 访问动态元素中的属性

Dynamic 访问动态元素中的属性,dynamic,textbox,blazor,property-binding,Dynamic,Textbox,Blazor,Property Binding,关于这一点,我正在尝试动态添加组件。我可以渲染这些组件,但我所需要的只是以动态方式影响这些组件的属性值。在我的例子中,我正在验证每个输入,并在blur事件中相应地向这些输入添加类 我知道我可以通过影响绑定到class属性的变量来实现这一点。但是我不知道如何获取特定元素来更改blur处理程序中的类 这就是我尝试过的 <ul> @for (int i = 0; i < userNames.Count; i++) { int j = i; /

关于这一点,我正在尝试动态添加组件。我可以渲染这些组件,但我所需要的只是以动态方式影响这些组件的属性值。在我的例子中,我正在验证每个输入,并在blur事件中相应地向这些输入添加类

我知道我可以通过影响绑定到class属性的变量来实现这一点。但是我不知道如何获取特定元素来更改blur处理程序中的类

这就是我尝试过的

    <ul>
    @for (int i = 0; i < userNames.Count; i++)
    {
        int j = i;  // copy i to be safe

 

        <li>
            <input type="text" class="@userNames[j]"  @onblur="onblur" />
        </li>
    }
</ul>

 

<button @onclick="AddUser">Add User</button>

 


@*to verify  the binding*@
@foreach (int userName in userNames)
{
    <p>@userName</p>
}

 

@code
{

 

    List<int> userNames = new List<int>() { 0 };

 

    public int count = 0;
    void AddUser()
    {
        count++;
        userNames.Add(count);
    }
    public void onblur(Microsoft.AspNetCore.Components.Web.FocusEventArgs args)
    {
      // Here I want to validate the correspoding input based on value and update the class property of the respective element.
    }
}
    @for(inti=0;i }
添加用户 @*验证绑定*@ @foreach(用户名中的int用户名) { @用户名

} @代码 { 列表用户名=新列表(){0}; 公共整数计数=0; void AddUser() { 计数++; 用户名。添加(计数); } public void onblur(Microsoft.AspNetCore.Components.Web.FocusEventArgs args) { //在这里,我想基于值验证相应的输入,并更新相应元素的class属性。 } }
我还想使用RenderFragment尝试同样的方法

任何帮助都将不胜感激