I'm using BeginCollectionItem and I'm trying to figure out how to get each individual collection value to do conditional show/hide logic. For example, if I have the following razor markup:
<div class="collection">
@using (Html.BeginCollectionItem(nameof(Item)))
{
<select class="select-class" id="select-id" asp-for="SelectExample">
<option value="a">a</option>
<option value="b">b</option>
</select>
<div class="show-if-b">b is selected</div>
}
</div>
I need to show the "show-if-b" div if the "b" element is selected, else it needs to hide. This logic needs to run onchange of the select and when the page loads ("b" could be saved) so I don't always have an event to attach to.
I've tried different approaches with jQuery .closest(), .find(), and .parents() but I can't seem to get the specific select value in each collection.
Any help is greatly appreciated.