Blazor 输入:onblur 抛出,oninput 工作正常
Blazor input: onblur throws, oninput works fine
<input type="text" @bind-value="Input1" @bind-value:event="oninput" />
<input type="text" @bind-value="Input2" @bind-value:event="onblur" />
@code
{
public string Input1 { get; set; }
public string Input2 { get; set; }
}
可以在第一个输入中输入文本,但一旦第二个输入失去焦点,就会引发此异常。
System.ArgumentException: Object of type
'Microsoft.AspNetCore.Components.Web.FocusEventArgs' cannot be
converted to type 'Microsoft.AspNetCore.Components.ChangeEventArgs'.
这感觉像是框架而不是我。有什么想法吗?
我在 .net 5.0 中使用 blazor 服务器。
复制并测试此代码:
<div>@message</div>
<input type="text" @bind-value="Input1" @bind-value:event="oninput" />
<input type="text" @bind-value="Input2" @onblur="@((args) => message= "The bulr event was fired." )" />
@code
{
private string message;
public string Input1 { get; set; }
public string Input2 { get; set; }
}
没问题。
当您使用这样的代码时:
@bind-value="Input2" @bind-value:event="onblur"
您实际上告诉编译器它应该生成将输入标记绑定到变量 Input2 的代码,并且绑定应该在 blur
事件被调用时发生,但是唉,绑定是在'change' 事件被调用。为了执行绑定,框架需要 ChangeEventArgs
参数,但它获取的是 FocusEventArgs
参数。如果你是框架,你会怎么做。她对你很好。只是一个小小的抗议。
<input type="text" @bind-value="Input1" @bind-value:event="oninput" />
<input type="text" @bind-value="Input2" @bind-value:event="onblur" />
@code
{
public string Input1 { get; set; }
public string Input2 { get; set; }
}
可以在第一个输入中输入文本,但一旦第二个输入失去焦点,就会引发此异常。
System.ArgumentException: Object of type 'Microsoft.AspNetCore.Components.Web.FocusEventArgs' cannot be converted to type 'Microsoft.AspNetCore.Components.ChangeEventArgs'.
这感觉像是框架而不是我。有什么想法吗?
我在 .net 5.0 中使用 blazor 服务器。
复制并测试此代码:
<div>@message</div>
<input type="text" @bind-value="Input1" @bind-value:event="oninput" />
<input type="text" @bind-value="Input2" @onblur="@((args) => message= "The bulr event was fired." )" />
@code
{
private string message;
public string Input1 { get; set; }
public string Input2 { get; set; }
}
没问题。
当您使用这样的代码时:
@bind-value="Input2" @bind-value:event="onblur"
您实际上告诉编译器它应该生成将输入标记绑定到变量 Input2 的代码,并且绑定应该在 blur
事件被调用时发生,但是唉,绑定是在'change' 事件被调用。为了执行绑定,框架需要 ChangeEventArgs
参数,但它获取的是 FocusEventArgs
参数。如果你是框架,你会怎么做。她对你很好。只是一个小小的抗议。