-1
How do I dropdown Sub Categories to bring the data according to what I chose in the categories table ? I can only pull from the database but I don’t know how I do the sub-category pull from the database depending on which category
<h1>Abrir Chamado</h1>
@if (_ListaCategorias.Count == 0)
{
<p>Carregando...</p>
}
else
{
<div class="row">
<div class="col-lg-3">
<select class="form-control">
<option> Selecione uma categoria </option>
@foreach (var cat in _ListaCategorias)
{
<option value="@cat.IdCategoria">@cat.Descricao</option>
}
</select>
</div>
</div>
}
</div>
<div class="container text-center">
<div class="row">
<div class="col-lg-3">
<select class="form-control">
<option value="1"> Selecione uma Subcategoria</option>
@foreach (var sub in _ListaSubCategorias)
{
<option value="@sub.">@sub.Descricao</option>
}
</select>
</div>
</div>
</div>
@code {
private List<Categoria> _ListaCategorias = new List<Categoria>();
private List<SubCategoria> _ListaSubCategorias = new List<SubCategoria>();
protected override async Task OnInitializedAsync()
{
Categoria _Categoria = new Categoria();
_ListaCategorias = await _Categoria.GetCategoriasAsync();
SubCategoria _SubCategoria = new SubCategoria();
_ListaSubCategorias = await _SubCategoria.GetSubCategoriasAsync();
}
private string Categoria { get; set; }
private string CheckSelected
{
get
{
return Categoria;
}
set
{
ChangeEventArgs selectedEventArgs = new ChangeEventArgs();
selectedEventArgs.Value = value;
OnChangeSelected(selectedEventArgs);
}
}
private void OnChangeSelected(ChangeEventArgs e)
{
if (e.Value.ToString() != string.Empty)
{
Categoria = e.Value.ToString();
}
}
}
I wanted to do it with the onchange but I don’t know how
– Alvaro Mora
The example worked out?
– novic