I am currently binding to @bind-Value= to get the selected Id but i would also like to bind and get the selected Text at the same time is there anyway of doing this. I tried @bind-CurrentValue but
that did not work
As binding only passes the field value, you would need to all JavaScript to get the option text value (as blazor code does not have access to the dom). While this is a pretty simple JavaScript, a better approach would be to have the list data in blazor,
and lookup the text based on the select value. You can build the option list from blazor data.
Member
1 Points
2 Posts
Blazor InputSelect bind to the the Selected text value
Jun 16, 2020 02:14 PM|aday|LINK
I am currently binding to @bind-Value= to get the selected Id but i would also like to bind and get the selected Text at the same time is there anyway of doing this. I tried @bind-CurrentValue but that did not work
All-Star
191741 Points
20952 Posts
ASPInsiders
Moderator
MVP
Re: Blazor InputSelect bind to the the Selected text value
Jun 16, 2020 02:46 PM|XIII|LINK
Hi,
please provide a code snippet when asking a question so we can better see what's going on/wrong.
Kris.
Working with Azure, chatbots, ASP.NET MVC, Web API, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Member
1 Points
2 Posts
Re: Blazor InputSelect bind to the the Selected text value
Jun 16, 2020 02:50 PM|aday|LINK
<inputselect class="ic-Input optionSelectionDropdowns" id="selDepartment" name="selDepartment" bind-value="Model.DepartmentId" bind-currentvalueasstring="Model.Department"></inputselect>
All-Star
58224 Points
15671 Posts
Re: Blazor InputSelect bind to the the Selected text value
Jun 16, 2020 02:50 PM|bruce (sqlwork.com)|LINK
As binding only passes the field value, you would need to all JavaScript to get the option text value (as blazor code does not have access to the dom). While this is a pretty simple JavaScript, a better approach would be to have the list data in blazor, and lookup the text based on the select value. You can build the option list from blazor data.