将 HTML 元素的值绑定到 Blazor 中的 C# 属性
Binding the value of a HTML element to a C# property in Blazor
在我正在构建的 blazor 应用程序中,我有以下 cshtml 代码,其中包含一个 <input>
元素供用户输入他们的姓名。我希望能够将输入元素的值绑定到 Blazor 页面的 c# 函数部分中的名称 属性。
我该怎么做?
我的代码如下:
@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; } = "";
}
将 @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;
}
在我正在构建的 blazor 应用程序中,我有以下 cshtml 代码,其中包含一个 <input>
元素供用户输入他们的姓名。我希望能够将输入元素的值绑定到 Blazor 页面的 c# 函数部分中的名称 属性。
我该怎么做?
我的代码如下:
@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; } = "";
}
将 @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;
}