I have been working with blazor in a practical way watching a tutorial. When I added the new option TO TWO and changed the titles to the view everything worked fine.
Now, when I started to touch the view a little more adding more features, when I reload the view, it doesn't reflect the changes.
It should be noted that the IDE does not show me errors or warnings, I did the tutorial several times to read letter by letter in case I have errors, I do not, and I cannot find the solution.
I tried deleting the Bin and OBJ folders but it doesn't work.
This is a snippet of the default NavMenu.Razor document which is where I add the To Dos option to the view
<div class="nav-item px-3">
<NavLink class="nav-link" href="todo">
<span class="oi oi-pencil" aria-hidden="true"></span> To Dos
</NavLink>
</div>
My Razor doc I created:
`@page "/todo"`
> <PageTitle>Mis To Dos</PageTitle>
> <h1>To Dos Pendientes: (@toDos.Count(todo => !todo.EstaCompletado))</h1>
<table>
<thead class= "py-5">
<th class="col-lg-3">Completado?</th>
<th class="col-lg-3">Titulo</th>
<th class="col-lg-3">Contenido</th>
<th class="col-lg-3">Fecha de Entrega</th>
</thead>
@foreach(var toDo in toDos)
{
<tr>
<td><input type="checkbox" @bind="toDo.EstaCompletado"/></td>
<td>@toDo.Titulo</td>
<td>@toDo.Contenido</td>
<td>@toDo.FechaEntrega</td>
</tr>
}
</table>
<h2>Añade Nuevos To Dos</h2>
<input placeholder="Añadir Titulo" @bind = "nuevoTitulo"/>
<input placeholder="Añadir Contenido" @bind="nuevoContenido" />
<button @onclick= AddToDo >Añadir To Do</button>
@code
{
private string? nuevoTitulo;
private string? nuevoContenido;
private List<ToDoItem> toDos = new();
private void AddToDo()
{
// Añade el To Do
if(!string.IsNullOrWhiteSpace(nuevoTitulo))
{
toDos.Add(new ToDoItem {
Titulo = nuevoTitulo,
Contenido = nuevoContenido ,
FechaEntrega = new DateOnly(2022,1,31)
});
nuevoTitulo = string.Empty;
}
}
}
My class that is used for the above:
public class ToDoItem
{
public int TodoItemId { get; set; }
public string? Titulo { get; set; }
public string? Contenido { get; set; }
public string? Responsable { get; set; }
public List<string> Etiquetas { get; set; } = new List<string>();
public DateOnly? FechaEntrega { get; set; }
public TimeOnly? HoraEntrega { get; set; }
public bool EstaCompletado { get; set; } = false;
}
This is the App.razor document that contains that error. I'll leave the coding in case it helps.
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
If I copy exactly the code you put in the ToDo.razor page it generates a compile error for
That's why it would be good to see your complete code, because the error you mention is a routing error.
I leave an example in an online repo if you want to download it (I uploaded it to see that the route is well prepared, you can download it and verify it)
and the path to the working page
I also updated so that it can work, only the modification was in the code that you sent here
by
In addition to placing the ToDoItem class inside an "Entities" folder (also import the namespaces in _Imports.razor)
I hope it helps or guides you.
Resolved. I don't have the technical answer, but I fixed it by deleting the ToDo.razor component and create another as Todo.razor.
The possible error was that in full development, I changed the name to .razor after having compiled the solution under the name of Todo.razor , so I assume that from here the problem was generated.
Recommendation: do not change the names of your files, after you have made compilations.
Likewise, I thank those who participated to help me.
See you soon ;).