【发布时间】:2022-01-29 21:41:57
【问题描述】:
我有带有 3 个 InputText 的 Blazor 表单
我需要的是,如果用户在名字或姓氏中输入字母,全名值将反映更改。但是如果用户更改全名字段,则不会影响名字和姓氏字段。
【问题讨论】:
我有带有 3 个 InputText 的 Blazor 表单
我需要的是,如果用户在名字或姓氏中输入字母,全名值将反映更改。但是如果用户更改全名字段,则不会影响名字和姓氏字段。
【问题讨论】:
你可以使用这个解决方案
<input type="text"
Id="FirstName"
class="form-control"
value="@RegisterModel.FirstName"
@oninput=@(e=> {
RegisterModel.FirstName = e.Value.ToString();
RegisterModel.FullName = $"{RegisterModel.FirstName} {RegisterModel.LastName}";
}) />
<input type="text"
Id="LastName"
class="form-control"
value="@RegisterModel.LastName"
@oninput=@(e=> {
RegisterModel.LastName = e.Value.ToString();
RegisterModel.FullName = $"{RegisterModel.FirstName} {RegisterModelLastName}";
}) />
<input type="text" Id="FullName" class="form-control" @bind-value="@RegisterModel.FullName" />
【讨论】: