C
C#13mo ago
deichor

✅ Blazor Tutorial (Todo List) Doesn't Work

Hello guys, I'm new in Blazor.
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo (@todos.Count(todo => !todo.IsDone))</h1>

<ul>
@foreach (var todo in todos)
{
<li>
<input type="checkbox" @bind="todo.IsDone" />
<input @bind="todo.Title" />
</li>
}
</ul>

<input placeholder="Something todo" @bind="newTodo" />
<button @onclick="AddTodo">Add todo</button>

@code {
private List<TodoItem> todos = new();
private string? newTodo;

private void AddTodo()
{
if (!string.IsNullOrWhiteSpace(newTodo))
{
todos.Add(new TodoItem { Title = newTodo });
newTodo = string.Empty;
}
}
}
@page "/todo"

<PageTitle>Todo</PageTitle>

<h1>Todo (@todos.Count(todo => !todo.IsDone))</h1>

<ul>
@foreach (var todo in todos)
{
<li>
<input type="checkbox" @bind="todo.IsDone" />
<input @bind="todo.Title" />
</li>
}
</ul>

<input placeholder="Something todo" @bind="newTodo" />
<button @onclick="AddTodo">Add todo</button>

@code {
private List<TodoItem> todos = new();
private string? newTodo;

private void AddTodo()
{
if (!string.IsNullOrWhiteSpace(newTodo))
{
todos.Add(new TodoItem { Title = newTodo });
newTodo = string.Empty;
}
}
}
This code published by Microsoft. (https://learn.microsoft.com/tr-tr/aspnet/core/blazor/tutorials/build-a-blazor-app?view=aspnetcore-8.0) I click on the button, but nothing is added to the list.
Blazor Yapılacaklar listesi uygulaması oluşturma
Adım adım uygulama Blazor oluşturma.
1 Reply
deichor
deichorOP13mo ago
/closed closed. .closed
Want results from more Discord servers?
Add your server