在我正在构建的blazor应用程序中,我有以下cshtml代码,其中包含<input>
元素,供用户输入其名称。我希望能够将input元素的值绑定到blazor页面的c#functions部分中的Name属性。
我该怎么做?
我的代码如下:
@page "/nameUpload"
<p>
//This is the input element that I would like to bind
Enter your name: <input type="text" ><br />
</p>
@functions {
//This is the property that I want to bind the input to
private string Name { get; set; } = "";
}
答案 0 :(得分:3)
将@bind
属性与input
一起使用。
@page "/nameUpload"
<p>
@* This is the input element that I would like to bind *@
Enter your name: <input type="text" @bind(name) />
<br />
</p>
@functions {
@* This is the property that I want to bind the input to *@
string name;
}