簡體   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