英文:
How do I get simple blazor wasm 2 way binding setup?
问题
I'm scratching my head on why this two-way binding does not work.
I'm binding to a string property on the page called result. This binding works for any initial values, and I see it set on my input text box.
But when I change the value programmatically to another value, the textbox still shows the old value. If I change the textbox value, the result property is also updated.
A small sample of the issue: Link to the sample
@page "/"
<input type="text" @bind-value="@result">
<input type="button" onclick="ChangeText" value="Submit" />
<p>@result</p>
@code {
protected string result = "Hello";
private void ChangeText()
{
result = "World";
}
}
英文:
I'm scratching my head on why this two way binding does not work.
I'm binding to a string property on the page called result. This binding works for any initial values, and I see it set on my input text box.
But when I change the value programmatically to another value, the textbox still shows the old value. If I change the textbox value, the result property is also updated.
A small sample of the issue: https://blazorfiddle.com/s/t0t4wpsv
@page "/"
<input type="text" @bind-value=@result>
<input type="button" onclick="ChangeText" value="Submit" />
<p>@result</p>
@code {
protected string result = "Hello";
private void ChangeText()
{
result = "World";
}
}
答案1
得分: 2
将您的输入控件的onclick
事件更改为:
<input type="button" @onclick="ChangeText" value="提交" />
英文:
Change your input control onclick event to:
<input type="button" @onclick="ChangeText" value="Submit" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论