0

I wrote the codes short due to the maximum code text length.

I'm trying use Datatables. Datatables configure like this..

  var table = $('#myTable').DataTable({
        "destroy": true,
        "scrollY": "500",

        "scrollX": true,
        "processing": true,
        "ajax": {
            "url": "/GetData/GetWeeklyData"
        },
        "columns": [
            {"data": "RecordDate"}
        ]
    });

But recordDate value format is /Date(-62135596800000)/

image

GetWeeklyDate is;

  public List<DefaultLogs> GetWeeklyData()
    {
        try
        {
            var client = new MongoClient(_appSettings.MongoClient);
            var filter = Builders<DefaultLogs>.Filter;
            var database = client.GetDatabase(_appSettings.MongoDbName);
            var collection = database.GetCollection<DefaultLogs>(_appSettings.CollFilteredLogs);

            var endDate = DateTime.Now;
            var startDate = endDate.AddDays(-7);

            var query = filter.Gte(x => x.RecordDate, new BsonDateTime(startDate)) & filter.Lte(x => x.RecordDate, new BsonDateTime(endDate));

            var result = collection.Find(query).ToList();
            return result;
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception.Message);
            return null;
        }
    }

Data model;

  public class DefaultLogs
{
  
    public DateTime LogDate { get; set; }
    
}

Datetime value is correct in C# side.I think I need to send it as String.How can I?

6
  • /Date(62135596800000)/ looks like the default DateTime serialisation of ASP.Net. What version are you using? Commented Dec 22, 2021 at 10:44
  • .Net Framework 4.7.2 Commented Dec 22, 2021 at 10:46
  • You should probably configure Json.Net to handle JSON (de)serialization. Commented Dec 22, 2021 at 10:47
  • Does this answer your question? ASP.NET MVC Controller.Json DateTime Serialization vs NewtonSoft Json DateTime Serialization Commented Dec 22, 2021 at 10:48
  • Unfortunately, Datatables did not accept Newtonsoft serialization. Commented Dec 22, 2021 at 11:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.