In the blazor docs they are able to add a search bar to a MudDataGrid using a MudTextField, and then they bind it to a string. But when I try to do the same, it says:
Cannot convert source type 'Models.Customer' to target type 'string'
at the @bind-value
<MudDataGrid T="Customer" MultiSelection="true" Items="@_salesHistory" SortMode="SortMode.Multiple" Filterable="true" QuickFilter="QuickFilter"
Hideable="true">
<ToolBarContent>
<MudText Typo="Typo.h6">Periodic Elements</MudText>
<MudSpacer />
<MudTextField @bind-Value="_searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
</ToolBarContent>
<Columns>
<PropertyColumn Property="x => x.AccountID" Title="Account ID" Sortable="false" Filterable="false" />
<PropertyColumn Property="x => x.CurrentDateTime" Title="Current DateTime" Sortable="false" Filterable="false" />
</Columns>
<PagerContent>
<MudDataGridPager T="Customer" />
</PagerContent>
</MudDataGrid>
@code {
private string _searchString;
I’ve tried using @oninput and ValueChanged instead of @bind-value, but I ran into the same issue. I’ve also tried copying the exact code from the MudBlazor docs and got the same error. Taking the MudTextField out of the MudDataGrid makes it work like intended. The only difference is my model, am I missing something obvious?
user25132623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.