相关疑难解决方法(0)

使用 Ctrl +V 组合键时,是否有方法更新附加到 Blazor 中的输入文本项的绑定变量?

我有这个输入来捕获电话号码。当用户输入数字并按“Enter”键时,会触发“KeyWasPressed”方法并进行一些验证。这按预期工作,但是......

例如,当用户从 Excel 复制并粘贴数字时,变量@Phone不会更新其值,因此当用户按“Enter”键时,验证会发送空值。

@Phone当某些文本粘贴到输入控件时,有没有办法刷新/更新变量?

这是我的代码片段:

<input type="number" class="form-control" @bind="@Phone" @onkeypress="@(async e => await KeyWasPressed(e))" placeholder="Client Phone Number" />

@code {

    string Phone { get; set; }

    private async Task GetClientInfo()
    {
        if(String.IsNullOrWhiteSpace(Phone))
        {
            notificationMessages = $"Add a phone number";
        }
        else
        {
            showSpinner = true;

            clientInfo = await ApiHelper.GetClientInfoByPhone(Phone);           

            if(clientInfo != null)
            {
                var singleViewId = clientInfo?.SingleViewId;
                var customerNumber = clientInfo?.Accounts?.FirstOrDefault().CustomerNumber;
                var status = clientInfo?.Accounts?.FirstOrDefault().Status;
                showClientInformation = true;

                var CrossSell = clientInfo?.Accounts[0]?.CrossSell; …
Run Code Online (Sandbox Code Playgroud)

keypress asp.net-core blazor blazor-server-side

3
推荐指数
1
解决办法
1445
查看次数