【问题标题】:Binding the value of a HTML element to a C# property in Blazor在 Blazor 中将 HTML 元素的值绑定到 C# 属性
【发布时间】:2018-09-05 01:04:36
【问题描述】:

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

【问题讨论】:

    标签: c# asp.net-core blazor


    【解决方案1】:

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

    【讨论】:

    • 完美运行。
    猜你喜欢
    • 2016-10-11
    • 2015-08-30
    • 2015-01-05
    • 1970-01-01
    • 2017-02-26
    • 2017-11-14
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多