【发布时间】:2017-01-18 01:10:32
【问题描述】:
我在 MVC ASP.NET 项目中使用 jquery 和 bootgrid。
使用实体框架,我得到了我想在网格中显示的数据,在数据库中看起来像这样:
1 Portal 2017-01-16 23:09:54.420 testFirstName testLastName testCompanyName
2 Portal 2017-01-14 14:37:33.750 John Doe Walmart
但是,当我将其转换为 Json 并将其传递回 bootgrid 时,JSON 看起来像
{"current":1,"rowCount":2,"rows":
[{"LeadId":1,"ScanDate":"\/Date(-62135571600000)\/","FirstName":"testFirstName","LastName":"testLastName","Company":"testCompanyName"},
{"LeadId":2,"ScanDate":"\/Date(-62135571600000)\/","FirstName":"John","LastName":"Doe","Company":"Walmart"}],"total":2}
ScanDate 值不正确。
在我的 bootgrid 视图中,我将列设置为:
<th data-column-id="ScanDate" data-formatter="date">Date Sent</th>
数据格式化如下:
return (date == null ? "" : date.substring(0, 10));
子字符串有效,因为我只看到上述 JSON 响应中数字的前 10 个字符。
为什么日期时间显示为数字?
我什至尝试将值转换为 JavaScript 中的日期
var convertDate = new Date(date);
但 convertDate 是未定义的,并且 convertDate.getDay / getHour() 是 NAN。
有什么想法吗?
【问题讨论】:
-
或者,您可能希望使用 Newtonsoft 的 Json.net 来生成 json,而不是使用 Microsoft 库。
标签: jquery json jquery-bootgrid