Blazor
Create a page:
dotnet new razorcomponent -n Todo -o Pages
First TODO page:
public class TodoItem {
public string? Title {get; set;}
public bool IsDone {get; set;} = false;
}
@page "/todo"
<h3>Todo (@todos.Count(todo => !todo.IsDone))</h3>
<ul>
@foreach (var todo in todos)
{
<li>
<input type="checkbox" @bind="todo.IsDone" />
<input @bind="todo.Title" />
</li>
}
</ul>
<input placeholder="something to do" @bind="newTodo" @bind:event="oninput" />
<button @onclick="AddItem">Add</button>
<p> todo is @newTodo </p>
@code {
private List<TodoItem> todos = new();
private string? newTodo;
private void AddItem() {
todos.Add(new TodoItem { Title = newTodo});
newTodo = string.Empty;
}
}
On parameter set:
@page "/counter/{startingValue}"
@code {
private int currentCount = 0;
[Parameter]
private int startingValue { get; set; } = 0
protected override void OnParametersSet()
{
currentCount = startingValue;
base.OnParametersSet();
}
}