When using the AutoComplete control in Blazor, binding to the SelectedItem property works perfectly for picking objects already present in your data collection. However, if a user types a custom string that doesn't match an item in the list, you might find that two-way binding directly to a Text property isn't exposed through a standard @bind-Text directive. This makes it difficult to capture free-form user input from your backing component.
Solution
While the internal architecture inherits a Text property, Blazor's strict binding handlers don't always expose it as a direct parameter wrapper. There are two efficient ways to extract or capture this text string depending on your architectural needs:
-
Capture Text in Real Time (Filtering Event): If you need the string as the user types, look at the
Filteringevent. You can read the raw input string directly out ofe.FilterStringwhenever a keystroke changes the control's search parameters. -
Access Text on Demand (Component Reference): If you need to read or clear the literal string dynamically (for instance, during a form submit action), capture a component reference using Blazor's
@refattribute. By referencing the backing control instance in your C# code block, you can pull or push raw strings straight through theAutoComplete.Textproperty.
<C1AutoComplete @ref="AutoComplete" T="Test" ></C1AutoComplete>
public C1AutoComplete<Test> AutoComplete = null;