Reputation: 41
I have problem with aggregating inputs from dynamically created combo boxes. In my view .cshtml I'm creating multiple elements with multiple choices as and I'm trying to set onClick trigger to this element like in snippet:
@foreach (var value in values)
{
<option onclick="@UpdateSelectedFilters(item.DisplayName, value)" value="@value" >@value</option>
}
But unfortunately this function "@UpdateSelectedFilters()" is executed on render of element, not on click event like i want to.
Upvotes: 0
Views: 87
Reputation: 41
Changing to javascript wasn't enough, model should be binded too in for example in asp-items
<select id="@name" class="form-control col-lg-3" style="margin-right: 10px; margin-top:10px" name="@name" asp-items="@options" onchange="UpdateSelectedFilters(this.name,this.value)">
Upvotes: 0
Reputation: 18159
UpdateSelectedFilters
is a js function,so you don't need to use @
before it.Try to use
<option onclick="UpdateSelectedFilters(@item.DisplayName, @value)" value="@value" >@value</option>
so that you can pass C# data to js function.
Upvotes: 1