I am trying to debug the OnSelectChanged
function. When I select an option, the execution does not hit the breakpoint I set on the line Opcion = opcion;
within the OnSelectChanged
function.
However, breakpoints in other functions are working correctly. Does anyone know how I can fix this?
I am using Blazor and .NET 8.
.razor
file:
<div class="row">
<div class="col-sm-3 p-3">
<select id="dropdown1" class="form-select" @onchange="@(e => OnSelectChanged(true, e.Value.ToString()))">
<option value="">Seleccione una opción</option>
<!-- Organizacion -->
@if (Opcion == "Organizacion")
{
}
<!-- Niveles Web -->
else if (Opcion != "Organizacion" && ListaCategoriasNivel1.Count > 0)
{
@foreach (var categoria in ListaCategoriasNivel1)
{
<option value="@categoria.CodigoNivel">@categoria.NombreNivel</option>
}
}
</select>
</div>
</div>
.razor.cs
file:
private void OnSelectChanged(bool status, string opcion)
{
Opcion = opcion;
}
I tried to create another function to see if it hits the breakpoint and that did not work either.
user23994105 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Please try InteractiveServer render mode.
.razor:
@page "/"
@rendermode InteractiveServer //Add this line
<div class="row">
<div class="col-sm-3 p-3">
<select id="dropdown1" class="form-select" @onchange="@(e => OnSelectChanged(true, e.Value.ToString()))">
<option value="">Seleccione una opción</option>
<!-- Organizacion -->
@if (Opcion == "Organizacion")
{
}
<!-- Niveles Web -->
else if (Opcion != "Organizacion" && ListaCategoriasNivel1.Count > 0)
{
@foreach (var categoria in ListaCategoriasNivel1)
{
<option value="@categoria.CodigoNivel">@categoria.NombreNivel</option>
}
}
</select>
</div>
</div>
.razor.cs:
public partial class Home
{
private string Opcion;
private List<Categoria> ListaCategoriasNivel1 =
[
new() { CodigoNivel = "1", NombreNivel = "0001" },
new() { CodigoNivel = "2", NombreNivel = "0002" },
new() { CodigoNivel = "3", NombreNivel = "0003" }
];
private void OnSelectChanged(bool status, string opcion)
{
Opcion = opcion;
}
}
public class Categoria
{
public string CodigoNivel { get; set; }
public string NombreNivel { get; set; }
}