Reputation: 811
Here is my code:
@page "/"
<button onclick="AddClick">Add</button>
@{
foreach (string i in StringList)
{
<div>@i</div>
}
}
@code{
public List<String> StringList { get; set; }=new List<string>() {"555","666"};
public void AddClick()
{
StringList.Add(DateTime.Now.ToString());
}
}
When I click the button, it does work yet.
I think it is because I haven't bound the List yet. Meanwhile, how can I bind the List?
Would you please help me? Thank you.
Upvotes: 1
Views: 2279
Reputation: 27538
Try add @ before onclick:
<button @onclick="AddClick">Add</button>
Upvotes: 7