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 8356015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:02:51+00:00 2026-06-09T10:02:51+00:00

I am using the JQuery Datatables plugin in an ASP.NET MVC project to display

  • 0

I am using the JQuery Datatables plugin in an ASP.NET MVC project to display some tabular data, which is in turn taken from a database using Entity Framework.

I have configured the Datatable to use ajax search and sort routines, and I am using an extension method to allow me to specify the name of a column to be sorted as a string. This works perfectly for most fields, but I get an error when trying to sort a field that contains a DateTime object.

View JQuery Code:

$('#Orders').dataTable({
        "bServerSide": true,
        "sAjaxSource": "/Suppliers/GetOrders/@Model.ID",
        "aaSorting": [[1, 'desc']],
        "bProcessing": true,
        bAutoWidth: false,
        "sPaginationType": "full_numbers",
        "aoColumns": [
                    { "bVisible": false },
                    { "sName": "OrderNumber",
                        "bSearchable": false,
                        "bSortable": true,
                        "fnRender": function (oObj) {
                            return '<a href=\"/Orders/View/' + oObj.aData[0] + '\">' + oObj.aData[1] + '</a>';
                        }
                    },
                    { "sName": "Supplier", "bSortable": true },
                    { "sName": "Client" },
                    { "sName": "OrderPlaced" },
                    { "sName": "OrderReceived"},
                    { "sName": "OrderedBy" },
                    { "sName": "Actions",
                      "fnRender": function (oObj) {
                            return '<a href=\"/Orders/View/' + oObj.aData[0] + '\">view</a>';
                        } 
                    }
                ]
    });

Controller code:

var data = DataContext.PartsOrders.Select(order => 
    new {
        order.SupplierID, 
        order.UniverseID, 
        order.ID, 
        order.OrderNumber, 
        Supplier = order.Supplier.Name, 
        Client = order.Job.Client.Name, 
        DateOrderPlaced = order.DateOrderPlaced, 
        order.DateOrderReceived, 
        OrderedBy = order.OrderedBy.Name 
    }).Where(x => x.SupplierID == id && x.UniverseID == Universe.ID);
data = data.OrderByField(columnNames[Convert.ToInt32(Request["iSortCol_0"])], Request["sSortDir_0"]);

And my ExtensionMethod is as follows, based on some code I found online. I’m not entirely sure I understand what this code is doing, which doesnt help me find my problem!

public static IQueryable<T> OrderByField<T>(this IQueryable<T> q, string SortField, string SortDirection)
    {

        var param = Expression.Parameter(typeof(T), "p");


        var prop = Expression.Property(param, SortField);

        var exp = Expression.Lambda(prop, param);

        string method = "";

        if (SortDirection == "asc")
            method = "OrderBy";
        else
            method = "OrderByDescending";

        Type[] types = new Type[] { q.ElementType, exp.Body.Type };

        var mce = Expression.Call(typeof(Queryable), method, types, q.Expression, exp);

        return q.Provider.CreateQuery<T>(mce);

    }

Finally, the error I get when trying to sort a column containing a date:

Instance property 'OrderPlaced' is not defined for type '<>f__AnonymousType6`9[System.Nullable`1[System.Int32],System.Int32,System.Int32,System.String,System.String,System.String,System.Nullable`1[System.DateTime],System.Nullable`1

this occurs in the extension method, on line var prop = Expression.Property(param, SortField);

  • 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-09T10:02:53+00:00Added an answer on June 9, 2026 at 10:02 am

    It’s simply a name conflict. <>f__AnonymousType6... is the anonymous type you create in DataContext.PartsOrders.Select(.... There is a property DateOrderPlaced in it. Change that to OrderPlaced, or change the OrderPlaced column in the dataTable in your javascript to DateOrderPlaced.

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

Sidebar

Related Questions

I'm using the jQuery DataTables plugin to display data being returned from an AJAX
I am using the jQuery plugin DataTables ( http://datatables.net ) for pagination, search capabilities
I'm using datatables plugin for jquery to show my data on the page. I
I'm using the jQuery DataTables plugin, which is working really great so far. However
I have been using the DataTables plugin for jQuery (http://www.datatables.net) to search, sort and
I'm currently working on a project using javascript and python with Jquery Datatables plugin
I'm using the dataTables jQuery plugin (which is totally awesome), but I'm having trouble
If you are using ASP.NET MVC how are you doing grid display? Rolled your
I am using jQuery Datatables plugin and I want to add some extra content
Here I am working with jquery data table plugin in asp.net page I'm currently

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.