下拉式排便

  • 本文关键字: c# html blazor
  • 更新时间 :
  • 英文 :


当一个下拉类别被自动选择为具有Onchange的类别的子类别时,我该怎么办?我找不到这个问题的解决方案,我需要帮助,请

<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 value="1"> Selecione uma categoria </option>
@foreach (var cat in _ListaCategorias)
{
<option value="@cat.IdCategoria">@cat.Descricao</option>
}
</select>
</div>
</div>
}
<div class="row">
<div class="col-lg-3">
<select class="form-control">
<option value="1"> Selecione uma Subcategoria</option>
@foreach (var cat in _ListaSubCategorias)
{
<option value="@cat.IdSubCategoria">@cat.Descricao</option>
}
</select>
</div>
</div>

@代码{

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();
}

}

下面的代码是一个Razor页面演示,向您展示如何实现我认为您正在努力实现的目标。您可能需要进行查询以获取子类别。我还向CCD_ 1添加了一个setter;事件";当国家发生变化时。您需要将其适应您的代码。

@page "/subcategory"
<h3>SubCategory</h3>
<span>Continent/Country</span>
<select @bind="Continent" placeholder="Choose a Continent">
@foreach (var continent in Continents)
{
<option value="@continent">@continent</option>
}
</select>
@if (Countries.Count > 0)
{
<select @bind="_country">
<option value="">Select a Country</option>
@foreach (var country in Countries)
{
<option value="@country">@country</option>
}
</select>
}
<div class="m-3">Country Selected: @_country</div>
@code {
class Model
{
public string Country { get; set; }
public string Continent { get; set; }
}
List<Model> models = new List<Model>()
{
new Model {Country = "UK", Continent = "Europe"},
new Model {Country = "Spain", Continent = "Europe"},
new Model {Country = "Portugal", Continent = "Europe"},
new Model {Country = "Thailand", Continent = "Asia"},
new Model {Country = "Singapore", Continent = "Asia"},
new Model {Country = "Brazil", Continent = "South America"},
new Model {Country = "Chile", Continent = "South America"},
};
IEnumerable<string> Continents
=> models.Select(item => item.Continent).Distinct();
List<string> Countries
=> models.Where(item => item.Continent.Equals(_continent)).Select(item => item.Country).ToList() ?? new List<string>();
string Continent
{
get => _continent;
set
{
if (!_continent.Equals(value))
{
_continent = value;
_country = string.Empty;
}
}
}
string Country
{
get => _country;
set
{
if (!_country.Equals(value))
{
_country = value;
// do whatever
}
}
}

string _continent = string.Empty;
string _country = string.Empty;
protected override Task OnInitializedAsync()
{
// Do what initializing you need to do here
return base.OnInitializedAsync();
}
}

相关内容

  • 没有找到相关文章