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

  • Home
  • SEARCH
  • 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 8170633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:11:15+00:00 2026-06-06T21:11:15+00:00

I have an action which returns JSON to a jQuery datatable . The data

  • 0

I have an action which returns JSON to a jQuery datatable. The data returned can be filtered depending on the params passed to it. Here’s the code:

public ActionResult IndexAjaxHandler(jQueryDataTableParamModel parameters) {
    var data = _mailingListRep.GetAllWithinAccount();
    IEnumerable<MailingList> filtered;

    // Filtering - THIS DOES NOT WORK!
    if (!string.IsNullOrEmpty(parameters.sSearch)) {
        filtered = data.Where(c => 
            c.MailingListName.Contains(parameters.sSearch) ||
            ((c.IsDoubleOptIn) ? "Yes" : "No").Contains(parameters.sSearch, StringComparison.OrdinalIgnoreCase) ||
            c.Created.ToString("dd MMM yyyy").Contains(parameters.sSearch) ||
            c.ActiveMembers.Count().ToString().Contains(parameters.sSearch) ||
        c.AvailableSegments.Count().ToString().Contains(parameters.sSearch)
        );
    }
    else {
        filtered = data;
    }

    // create json object
    // return;
}

The problem is this gives me the following error:

Method ‘Boolean Contains(System.String, System.String, System.StringComparison)’ has no supported translation to SQL.

BUT

In the same controller is another action which also returns JSON to a datatable, which uses the exact same filtering method and it works fine!

public ActionResult ViewDeletedAjaxHandler(int id, jQueryDataTableParamModel parameters) {
    var list = _mailingListRep.GetByIDWithinAccount(id);
    var data = list.DeletedMembers;
    IEnumerable<MailingListMember> filtered;

    // Filtering - THIS WORKS, NO ERRORS!
    if (!string.IsNullOrEmpty(parameters.sSearch)) {
        filtered = data.Where(c => 
            c.EmailAddress.Contains(parameters.sSearch, StringComparison.OrdinalIgnoreCase) ||
            c.UnsubscribedDate.ToString("dd MMM yyyy").Contains(parameters.sSearch, StringComparison.OrdinalIgnoreCase)
        );
    }
    else {
        filtered = data;
    }

    // create json object
    // return;
}

Does anyone know why this is?

For reference, Contains(string, comparison) is an extension method:

public static bool Contains(this string source, string toCheck, StringComparison comp) {
    return source.IndexOf(toCheck, comp) >= 0;
}

I understand what the error means, it is the fact that the code works in 1 action, but not the other than has me completely confused.

Thanks for any help in advance.

  • 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-06T21:11:18+00:00Added an answer on June 6, 2026 at 9:11 pm

    Your first filter that does not work is applied to a IQueryable<T> and your second that works is applied to an IEnumerable<T>.
    When applied to an IQueryable<T>, the filter must be translateable to SQL, whereas when it is used on an IEnumerable<T> the filter is evaluated in memory.

    To make the first one work, you need to either call ToList() to force the results into memory before applying the filter, or use the helper methods available from the EntityFunctions class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AJAX controller action which returns JSON. The returned JSON is handled
I have controller action which returns JsonResult and is consumed by jquery ajax get
Well I have a problem reading the JSON data in jQuery, which is outputted
I have a search action that returns a json response object which is basically
I have a jquery routine that calls an MVC action which will do a
Inside of a jQuery plugin I made I have: $.getJSON(base_url,{ agenda_id:defaults.id, action:defaults.action+defaults.type, output:defaults.output },function(json){
I have an ajax call in jquery which returns 4 different arrays. 3 of
Scenario: We have MVC 4.0 web application with display myOrders which returns json result
I have an action which create QMessageBox. In that dialog I want to print
I have controller users . In this controller I have action account which is

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.