I posted a question earlier but I explained my problem just vaguely and I deleted it and started another. I'm trying to implement a query-based filter where the user fills in groups of (attribute, operator, value). The page has a paged list of elements (the model of the view is this list), that all belong to a certain other entity that doesn't really matter here, linked to it by an Id that is passed as a parameter. The controller action looks like this:
public async Task<IActionResult> Index(Guid ideaId,
int? page,
List<FilterItemViewModel> data)
{
//here I take the data, and filter the elements and then return them;
//the 'data' list can be empty and indeed it is when you first access the page;
//in that case I just return all elements that have their 'IdeaId'
//field equal to the parameter 'ideaId'
return View(await PagedList<FeatureViewModel>.CreateAsync(model.AsNoTracking(),
page ?? 1,
int.Parse(_configuration["Pagination:ItemsPerPage"])));
}
About the filter itself, the user can add as many filter groups as they want. After they press 'Filter' I collect in javascript all the values he entered, I put them in an array and here comes the part I'm stuck at. I need to send it to the Index action and reload with the new info. I tried ajax like this:
$.ajax({
url: '/Feature/Index',
data: finalParams,
type: 'POST',
success: function (response) {
//response here is the HTML and scripts and style of the page and it
//returns what it should after filtering but I need to access the page itself
},
error: function () {
alert("pffff");
}
});
Note that 'finalParams' is an objects with fields named 'ideaId', 'page', 'data', where 'ideaId' and 'page' are taken from the current location and data is the array in which I collected the user input.
How can I get to the page returned from that response? Or is there any way I can send the data to the controller and have the different set returned?