繁体   English   中英

将HTML元素的值绑定到Blazor中的C#属性

[英]Binding the value of a HTML element to a C# property in Blazor

在我正在构建的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; } = "";
 }

input使用@bind属性。

@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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM