Return Date object as json data in Asp.net MVC
10/6/2021 2:09:05 PM
I was working on Sitecore Mvc Jsonresult action method type , trying to return Json date object to AJax call.
I was getting an unknown format of date in return, which was very painful to get the solutin at that time very quickly. I had strict deadline to implement timer or count down timer in a page.
I googled a lot , found different kind of jsondatetime handler used by others, i found them complex. Finally i got the trick and tried, and worked.
My initial Jsonresult action method was:
Which returns date for in json : /Date(1655718400000)/
I was unble to convert it to proper date format in js/jquery client side.
To overcome this problem i just convert the date object to json object in action method, Like below code
// Convert the date object to json format
var response = JsonConvert.SerializeObject(TimerModel.TickerTimer);
Json return: "\"2021-11-11T22:30:00Z\""
Now it is easy to conver this json date covert or deserilize and convert it to a normal date format in client side in javascrit or jQuery.
Let me know if it not works in yourside.
0 Comments on this post
Comments(0)||Login to Comments
- see more..
Issues Resolved (6)
Sitecore 9.3 (1)
International Business (1)
Innovations in Industries (3)
Supply Chain Management (1)
Industrial Engineering (14)
Sitecore 10 (4)
Cloud Computing (1)
Online Courses (1)
Online Resources (2)
Blazor WebAssembly (2)
Sitecore form (1)
MS Sql Server (1)
Angular 11 (2)
Automobile Engineering (5)
Sitecore powershell (1)
Microservice Architecture (1)
Sitecore Interview Questions (2)
Dotnet interview questions (1)
Sitecore useful links (1)
Solr Search (2)