1

I am trying to retrieve the dates from database into datatable but I am getting the below problem. your help will be highly appreciated.

\/Date(1239018869048)\/

Error

Controller:

  public ActionResult GetData()
    {

        List<LeavePeriod> leavindb = _dbContext.LeavePeriod.ToList<LeavePeriod>();
        return Json(new { data = leavindb }, JsonRequestBehavior.AllowGet);
    }

view:

@section scripts
  {


   <script>
    var Popup, dataTable;
    $(document).ready(function () {

        dataTable = $('#leaveperiod').DataTable({
            "ajax": {
                "url": "/LeaveSetup/GetData",
                "type": "GET",
                "datatype": "json"
            },
            "columns": [
                //{ "data": "LeavePeriodId" },
                {
                    "data":"StartDate"

                },
                { "data": "EndDate" },

                {
                    "data": "LeavePeriodId",
                    "render": function(data) {
                        return "<a class='btn btn-default btn-sm' onclick=PopupForm('@Url.Action("AddOrEdit", "LeaveSetup")/" +data +"')><i class='fa fa-pencil'></i> Edit</a>" +"<a class='btn btn-danger  btn-sm'style='margin-left:5px;'onclick=Delete(" +data +") ><i class='fa fa-trash'></> Delete</a>";
                    },
                    "orderable": false,
                    "searchable": false,
                    "width": "120px"
                }
            ]
        //    ,
        //    "language": { "emptyTable": "No data found,Please click on <b>Add New</b> Button" }
        });
    });

    function PopupForm(url) {

        var formDiv = $('<div/>');
        $.get(url)
            .done(function (response) {
                //start here

                //end
                formDiv.html(response);
                Popup = formDiv.dialog({
                    autoOpen: true,
                    resizable: false,
                    title: 'Fill LeavePeriod Details',
                    height: 500,
                    width: 700,
                    close: function () {
                        Popup.dialog('destroy').remove();
                    }
                });
            });
    }


</script>

}
Mr. Pyramid
  • 3,855
  • 5
  • 32
  • 56
Basharmal
  • 1,313
  • 10
  • 30
  • what serialiser are you using on the server-side? Usually this strange date format is only seen in older WCF or ASMX services. MVC and Web API usually use JSON.NET to serialise data to JSON, which doesn't use that format. – ADyson Oct 13 '17 at 14:18
  • i don't know which one to use if you can help me – Basharmal Oct 13 '17 at 14:55
  • Use JSON.NET. Like I just said, that's the one which will produce an ISO date format which can be read natively by Javascript. – ADyson Oct 13 '17 at 14:56
  • 1
    It is unclear why you have a field called `LeavePeriodId` or `Month` that would show a `DateTime` datatype. Both of these could be represented by an `int` – NightOwl888 Oct 13 '17 at 19:19
  • could anyone give me a little details – Basharmal Oct 14 '17 at 08:21
  • can anyone tell me how to do it please please please – Basharmal Oct 14 '17 at 11:48
  • how to do what? We've just explained above what you can do. It's easy to google. There's also information contained the marked duplicate question which you can use to help you. No need for us to write it all over again. In particular see Approach 2 in this answer: https://stackoverflow.com/a/9302054/5947043 – ADyson Oct 14 '17 at 18:20

0 Answers0