Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Using Blazor, rendering elements in a for loop and can't get @bind to work with a dictionary by index

$
0
0

Let's define the dictionary I'm using as searchBoardGames[image.Id]

The select is in a foreach loop so I can render multiple select elements because what I'm trying to do is collect data from the user for multiple entries, but using the same list of gameIds. The @foreach loop with the <select> would be something like this:

<div class="image-gallery">    @foreach (var image in images)    {<div class="image-item"><img src="data:image/png;base64,@Convert.ToBase64String(image.ImageData)" alt="Unknown Image" /><div id="boardGameSelect" class="board-game-select">                @if (searchResults.ContainsKey(image.Id) && searchResults[image.Id].Any())                {<select id="@selectInputId" @bind="searchBoardGames[image.Id]"><option value="">-- Select a Board Game --</option>                        @foreach (var game in searchResults[image.Id])                        {<option value="@game.Id">@game.Name</option>                        }</select>                }</div></div>    }</div>

So now the problem is the @bind=searchBoardGames[image.Id] isn't going to work, but I can't figure out how to get around this problem. I can't add an @onchange because that's used by @bind and I haven't been able to construct a method that could return something because it needs to be bound to a Property, not the value of some returned variable.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>