0

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?

Megid
  • 105
  • 12
  • Is your problem that the data parameter in the controller is empty? Did you take a look at [this post](https://stackoverflow.com/questions/21288462/c-sharp-mvc-4-passing-javascript-array-in-view-to-controller) – Steve T Jan 15 '18 at 13:02
  • No, the response contains the HTML returned and I specifically placed a 'div' in the view which is empty when the data list from controller is null and has a value from the list if it's not. The HTML returned shows the right text inside that div. But my problem is that I don't need the HTML string, I need to get to that page, to show it. – Megid Jan 15 '18 at 13:09

0 Answers0