【问题标题】:Blazor - Binding data without using any event (onChange, onInput ...)Blazor - 绑定数据而不使用任何事件(onChange,onInput ...)
【发布时间】:2020-05-30 07:59:46
【问题描述】:

我们必须在一个动作中更新数据到模型中(比如保存)。 我们的想法:不希望每次 HTML 元素“失去焦点”时都经常调用服务器。最后,我们要在提交时更新值。

<div>
    <label>Name</label>
    <input type="text" value="@student.Name" />
    <br />
    <label>Age</label>
    <input type="text" value="@student.Age" />
    <br />
    <input type="submit" @onclick="Save" />
</div>

@code {
    Student student = new Student();

    private void Save()
    {
        // At this stage - the value should be updated to the model.
    } 
}

【问题讨论】:

  • 使用 blazor wasm,或者一堆 javascript 和 JS 互操作

标签: blazor blazor-server-side


【解决方案1】:

您是否尝试过更新 Visual Studio 和 .Net Framework Core?因为既然我这样做了,它会自动执行您要求的操作,每次输入文本失去焦点时都会保存数据,我不知道为什么,如果它是错误或默认功能。 A video I did showcasing this issue。你可以在代码上看到我没有做任何事情来实现这一点。

【讨论】:

  • 实际上我不想在每次文本框失去焦点时保存数据。
猜你喜欢
  • 2019-11-08
  • 2019-12-05
  • 1970-01-01
  • 2021-04-24
  • 2020-07-07
  • 1970-01-01
  • 2019-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多