My model looks like this
public partial class EditModel
{
public int Id { get; set; }
...
public string Item { get; set; }
}
My SearchItems method header looks like this
protected async Task<IEnumerable<ListItem>> SearchItems(string value)
which returns 'list' of these
public partial class ListItem
{
public string Id { get; set; }
public string Name { get; set; }
}
How do I get my MudAutocomplete to show the Name, yet return/bind the Id?
<MudAutocomplete T="ListItem" Label="Select item" @bind-Value="EditModel.Item"
Clearable="true"
MinCharacters="4" SearchFunc="@SearchItems"
ToStringFunc="@(i => i==null ? null : $"{i.Id} [{i.Name}]")"
SelectValueOnTab="true"/>
on the @bind-Value, Visual studio shows this error
...cannot convert from 'string' to 'EditModel.Item'
ListItem
object to aEditModel.Item
object - they are different objects. What you need to do is to remove theListItem
object, you don't need it - just filter over a list of EditModels and then you will be properly binding EditModels to EditModels. – Dispart