如何将集合绑定到 Blazor 中的表?

Posted

技术标签:

【中文标题】如何将集合绑定到 Blazor 中的表?【英文标题】:How to bind a collection to a table in Blazor? 【发布时间】:2020-12-06 10:22:21 【问题描述】:

我有一个 razor 组件,其中包括一个简单的表,我想将其用作输入表,如下所示:

<label for="dependencies">Abhängigkeiten</label>
<table class="table table-striped">
  <tr>
    <th scope="col">Name</th>
    <th scope="col">Version</th>
    <th scope="col">Entfernen</th>
  </tr>
</table>

在代码部分中,我有一个 IEnumerable&lt;T&gt; 类型的属性,我想动态绑定到表,因此集合的内容会绑定到表。我必须这样做哪些选项?

【问题讨论】:

【参考方案1】:
@foreach(var item in AllItems)

  <tr @key=item>
    <td>@item.Name
  </tr>

如果需要,你也可以&lt;InputText @bind=item.Name/&gt;

【讨论】:

以上是关于如何将集合绑定到 Blazor 中的表?的主要内容,如果未能解决你的问题,请参考以下文章