Well, I have a dropdown and did it on my razor page and it works fine. But I would like to make a component of this dropdown, since I need it for other pages of my application. However, I copied all the relevant code to a razor file in the shared folder and it does not bind the value to the usuarioId variable! Could you help me? I've tried numerous solutions from other topics on this forum, tried to copy DropDown from the examples, but nothing worked ...
<RadzenDropDown FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"
Data=@(ListUser) TextProperty="@nameof(Result.name)" TValue="int"
ValueProperty="@nameof(Result.id)" @bind-Value="userId" Style="text-align:left" />
Taking advantage, ListarUsuarios also has the CPF / CNPJ number, which is the identity number of the person or company. Would it be possible for the dropdown filter to search both by name and number?
We lack the full context here and can't help right away. I suggest you compare the working page with the component. Other than that the DropDown declaration looks correct.
No, the DropDown searches only by the property specified via TextProperty.
And would it be possible to specify more than one property in the TextProperty?
No, only one property can be specified via TextProperty. You can check the DropDownDataGrid which can filter by all string columns: https://blazor.radzen.com/dropdown-datagrid
Ok, that's the full code of my component
@using libModels.ModelosWeb;
@using Radzen.Blazor;
@using Services;
@using Services.Model;
@using Web.Client.Classes;
@using Newtonsoft.Json;
@inject SvcHttpRequest SvcHttp;
@inject ServerAuthenticationStateProvider authentication;
@inject WebClientConfigurations configurations;
@code{
public string TokenJwt { get; set; }
public AlertComponent Alert { get; set; }
protected LoadingComponent LoadComponent { get; set; } = new LoadingComponent();
protected List<Resultado> ListarUsuario { get; set; } = new List<Resultado>();
protected int usuarioId;
}
@code{
protected override async Task OnInitializedAsync()
{
TokenJwt = await authentication.GetTokenAsync();
await ListarUsuarios();
}
private async Task ListarUsuarios()
{
try
{
//LoadComponent.LoadingChange(true);
string path = configurations.linkWebApi + $"Compra/ListarTodosAtivos";
HttpResponseMessage result = await SvcHttp.GetAsync(path, TokenJwt);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
ListarUsuario = JsonConvert.DeserializeObject<List<Resultado>>(await result.Content.ReadAsStringAsync());
StateHasChanged();
}
else
{
result.EnsureSuccessStatusCode();
}
}
finally
{
LoadComponent.LoadingChange(false);
}
}
public int getUsuarioId()
{
return usuarioId;
}
private void ShowMessage(MdlInfoUser mdlInfo)
{
if (mdlInfo.Nivel == Classes.LogLevel.Warn)
{
Alert.ShowMessage(EN_Alert.AlertWarning, mdlInfo.Mensagem);
}
else if (mdlInfo.Nivel == Classes.LogLevel.Error)
{
Alert.ShowMessage(EN_Alert.AlertDanger, mdlInfo.Mensagem);
}
else
{
Alert.ShowMessage(EN_Alert.AlertInfo, mdlInfo.Mensagem);
}
}
}
<label for="ddrListaCategorias" class="pr-2">Selecione o cliente:</label>
<RadzenDropDown FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"
Data=@(ListarUsuario) TextProperty="@nameof(Resultado.nome)" TValue="int"
ValueProperty="@nameof(Resultado.id)" @bind-Value="usuarioId" Style="text-align:left" />
And can I only display names in the dropdown, without the DataGrid format?
Code looks fine to me. What exactly "does not work" mean in this case? What happens when you select a value from the dropdown?
After I select a client, the usuarioId variable (which is in the bindValue) remains equal to 0, it does not receive the user id.
@korchev, any ideas about what I'm doing wrong?
No ideas. I will need a minimal reproduction in order to tell more.
@korchev, if you need more details about the code or an explanation of what is being done there, let me know.