C# 按下按钮时,Blazor服务器应用程序中的输入字段未绑定

C# 按下按钮时,Blazor服务器应用程序中的输入字段未绑定,c#,asp.net,blazor,C#,Asp.net,Blazor,我在我的应用程序中遇到了奇怪的行为,当我在PC上调试它时,工作正常,当我将它发布到Azure时,当我按下“登录”按钮时,密码输入没有绑定。要绑定它,我必须单击其他地方,然后按“登录”按钮。 这是我的密码: <AuthorizeView> <Authorized> <b>Hello, @context.User.Identity.Name!</b> <a class="ml-md-auto btn btn-primary"

我在我的应用程序中遇到了奇怪的行为,当我在PC上调试它时,工作正常,当我将它发布到Azure时,当我按下“登录”按钮时,密码输入没有绑定。要绑定它,我必须单击其他地方,然后按“登录”按钮。 这是我的密码:

<AuthorizeView>
<Authorized>
    <b>Hello, @context.User.Identity.Name!</b>
    <a class="ml-md-auto btn btn-primary"
       href="/logout?returnUrl=/"
       target="_top">Logout</a>
</Authorized>
<NotAuthorized>
    <input type="text"
           placeholder="User Name"
           @bind="@Username" />
    &nbsp;&nbsp;
    <input type="password"
           placeholder="Password"
           @bind="@Password" />
    <a class="ml-md-auto btn btn-primary"
       href="/login?paramUsername=@encode(@Username)&paramPassword=@encode(@Password)"
       target="_top">Login</a>
@code {
     string Username = "";
     string Password = "";
     private string encode(string param)
     {
         return HttpUtility.UrlEncode(param);
     }
}

@代码{
字符串Username=“”;
字符串密码=”;
私有字符串编码(字符串参数)
{
返回HttpUtility.UrlEncode(param);
}
}

这种情况的发生是因为只有当您将焦点从输入中移开时才设置该值,因此您应该使用一种方法,在每次按键时更新该值

<input 
    type="password"
    placeholder="Password"
    @bind="@Password" 
    @bind:event="oninput" // update value on every key press
/>