I have a dropdown menu on my webpage, and I want to trigger a controller call every time the selection changes, passing the chosen value as a parameter.
<form asp-controller="CompetitorsMarketplace" asp-action="Index" method="get" class="form-filters">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Marketplace</label>
<select id="selectChangedValue" class="form-control" asp-for="MarketplaceName"
asp-items="Model.MarketplaceSelectList"></select>
</div>
</div>
<div class="col-md-3 text-left ">
<button class="btn btn-info btn-filter"><i class="fa fa-search"></i> Filter</button>
</div>
</div>
</form>
Controller
public IActionResult Index(CompetitorByMarketPlaceViewModel competitorByMarketPlaceViewModel, string textSearchMarketplace, int page = 1)
{
}
And here is what I attempted using JavaScript:
<script language="JavaScript">
$('#selectChangedValue').on('change', function () {
var postData = document.getElementById("selectChangedValue").value;
window.location = "/CompetitorsMarketplace/Index?textSearchMarketplace=" + postData;
});
</script>