0

在我正在构建的 blazor 应用程序中,我有以下 cshtml 代码,其中包含一个<input>供用户输入其姓名的元素。我希望能够将输入元素的值绑定到 blazor 页面的 c# 函数部分中的 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; } = "";
 }
4

1 回答 1

4

@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;
}
于 2018-03-26T19:31:06.677 回答