Skip to content

Instantly share code, notes, and snippets.

@sugimomoto
Created December 17, 2019 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugimomoto/ef2a779f702cd3c0de849e4040b85a53 to your computer and use it in GitHub Desktop.
Save sugimomoto/ef2a779f702cd3c0de849e4040b85a53 to your computer and use it in GitHub Desktop.
key directive test
@page "/"
@using System.Collections.Generic;
<h1>Hello, world!</h1>
Welcome to your new app.
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
@foreach (var person in People)
{
<tr @key="person">
<td><input type="text" @bind-value="person.name" /></td>
<td><input type="text" @bind-value="person.age" /></td>
</tr>
}
</tbody>
</table>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
@foreach (var person in People)
{
<tr @key="person">
<td><input type="text" @bind-value="person.name" /></td>
<td><input type="text" @bind-value="person.age" /></td>
</tr>
}
</tbody>
</table>
@code {
[Parameter]
public List<Person> People { get; set; }
protected override void OnInitialized()
{
this.People = new List<Person>();
People.Add(new Person() { name = "kazuya", age = 31 });
People.Add(new Person() { name = "takahashi", age = 32 });
}
public class Person
{
public string name { get; set; }
public int age { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment