Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8355737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:57:30+00:00 2026-06-09T09:57:30+00:00

I work on a ASP.NET MVC project that needs to be able to filter

  • 0

I work on a ASP.NET MVC project that needs to be able to filter data in an extensible way. I’ve decided to use a class to represent a single filter criterion (I am aware that it could be a Dictionary at this point, but I might need to add other properties later):

public class FilterCriterion
{
    public string FilterName { get; set; }

    public string FilterValue { get; set; }
}

And this is the controller method signature I had in mind that will return filtered data:

public JsonResult GetMultipleShowDetailsByFilter(IEnumerable<FilterCriterion> filters, int pageNumber, int itemsPerPage)

This method will be called from the web page (using JavaScript) and will return a JSON containing a set of entities that will be then displayed on the page.

I assume I will need some kind of converter that will accept the arguments in a raw state and create and enumerable object implementing IEnumerable<FilterCriterion>. Maybe I could use a ModelBinder, but I am not really sure how.

Can you nudge me in the right direction? Thanks.

EDIT:
I not pass an array as suggested. When I step into the controller, there is a correct number of items inside filters, but their properties (both FilterName and FilterValue) are null. Below I post the complete code as well as the contents of filter object on the client side. What am I doing wrong?
Javscript code:

function filterChanged() {
    var activeFilters = $(':checked');
    var filters = new Array();
    $.each(activeFilters, function (i, val) {
        var newItem = new Object();
        newItem.FilterName = $(val).attr('data-filter-type');
        newItem.FilterValue = $(val).attr('data-filter-value');
        filters[i] = newItem;
    });

    $.getJSON('../DatabaseApi/GetMultipleShowDetailsByFilter',
        {
            'filters': filters,
            'pageNumber': 1,
            'itemsPerPage': 10
        },
        function(data) {
            fill(data);
        });
}

How do the created object look (proof that there is data, taken from VS Immediate Window):

?filters
[[object Object],[object Object]]
    [0]: {...}
    [1]: {...}
    [prototype]: []
?filters[0]
{...}
    [prototype]: {...}
    FilterName: "Genre"
    FilterValue: "Animation"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:57:31+00:00Added an answer on June 9, 2026 at 9:57 am
    1. Change your controller signature to

      public JsonResult GetMultipleShowDetailsByFilter(FilterCriterion[] filters, int pageNumber, int itemsPerPage)
      
    2. use following POST structure:

      filters[0].FilterName = 'aaa'
      filters[0].FilterValue = 'bbbb'
      filters[1].FilterName = 'ccc'
      filters[1].FilterValue = 'ddd'
      ...
      filters[n].FilterName = 'xxx'
      filters[n].FilterValue = 'yyy'
      

      (you can easily do that with jQuery)

    One caveat: your index numbering should be contiguous, i.e. have no gaps.

    Update to topic starter’s update: you have to be very careful with POST structure. Nested JavaScript objects won’t do. Try using this one:

    function filterChanged() {
        var activeFilters = $(':checked');
        var data = {
            'pageNumber': 1,
            'itemsPerPage': 10
        }
        $.each(activeFilters, function (i, val) {
            data['filters[' + i + '].FilterName'] = $(val).attr('data-filter-type');
            data['filters[' + i + '].FilterValue'] = $(val).attr('data-filter-value');
        });
    
        $.getJSON('../DatabaseApi/GetMultipleShowDetailsByFilter',
            data,
            function(data) {
                fill(data);
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i was wondering if there is a way to use ASP.Net's Data annotation without
I work in a company that has over 70 asp.net mvc projects (very similar
I have an Asp.Net MVC project with the typical forms authentication that redirects the
I work in VS2010, ASP.NET MVC 2 project. The project was completed, it remains
I have a ASP.NET MVC project and i want to use jQuery on them.
I am currently starting a new ASP.NET MVC Project at work where we need
I'm planning work on a new project and am now tempted to use ASP.NET
Our ASP.NET MVC project uses MS SQL Server (for most of the data) and
The setup: Winform/ASP.NET MVC projects. Learning NHibernate SQL-Server driven apps I work with clients
Is it possible to setup ASP.NET MVC 2 to work with a MySQL database?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.