I've an ASP.NET proj. MVC Core with a series of tables. Each has a field called "year". In the _Layout, I've a dropdown list with the next 5 years (2017, 2018, ect). I'd like to receive in every action of the controller the value of the dropdown selection in order to apply the filter "by year" to the query.
_LAYOUT.CSHTML PAGE
<select name="EF_DROP" id="EF_DROP" class="btn btn-default" style="width:105px;" aria-haspopup="true" aria-expanded="true" type="button">
<option value="0">EF 2017</option>
<option value="1">EF 2018</option>
<option value="2">EF 2019</option>
<option value="3">EF 2020</option>
</select>
//this is my Jquery to set Hidden Fields
$(function () {
$("#EF_DROP").on("change", function () {
$("#YEAR").val($(this).find(":selected").text().substr(3, 4));
});
});
$(function () {
$("#YEAR").val($("#EF_DROP").find(":selected").text().substr(3, 4));
});
EACH VIEW PAGE
<input type="hidden" asp-for="YEAR" />
THE PROBLEM IS ON THE CONTROLLER:
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.MYTABLE.Include(a => a.RELATE)
.Where(x=>x.Year == **??**);
return View(await applicationDbContext.ToListAsync());
}
I've tried to add a Singleton but can't find the getValue from collection or with Request.Form["name"].... Someone can help me please? Thanks in advance.
<option value="2017">EF 2017</option>
– Anderson PimentelYEAR
. Just renameEF_DROP
toYEAR
. You also won't need any jQuery code. – Anderson Pimentel