Home » » Unable to retrieve Date Array object from c# to javascript?

Unable to retrieve Date Array object from c# to javascript?

Written By M.L on திங்கள், 10 அக்டோபர், 2011 | அக்டோபர் 10, 2011

I am trying to fetch Array of dates object from c# to javascript using below code but its returing in incorrect format like below-
\/Date(1309471200000)\/

Also tried Date.parse function but didn’t work.


$.getJSON("GetActivedates", function (validdates) {           
            $.each(datetemp in validdates)
            {
}
)};


Here is the c# routine which is returning Dates Array

public JsonResult GetActivedates()
        {
            Models.ReportViewModel dates = new Models.ReportViewModel();
            dates.ActiveDates = ValidActiveDates();
            return Json(dates.ActiveDates, JsonRequestBehavior.AllowGet);
        }


public DateTime[] ValidActiveDates()
        {
using (var db = new SalesMetadataModelContainer())
            {
                int i = 0;
                var reportdateList = db.SalesReports.Where(x => x.Audit.IsDeleted == false && x.IsVisible == true).Select(x => x.ReportDate).Distinct().ToList();
                DateTime[] activedate = new DateTime[reportdateList.Count];
                DateTime StrDate = System.DateTime.Today;
                foreach (var res in reportdateList)
                {
                    StrDate = res;
                    activedate[i++] = StrDate;
                }
                return activedate;
            }
        }

I have tried various work around but nothing works, any suggestions are most welcome!!

0 comments:

கருத்துரையிடுக

Popular Posts

General Category