Javascript DataTables从数据库中呈现错误的DateTime值
我在asp.NETMVC项目中使用datatable插件,绑定数据时它会呈现错误的日期时间值 数据库中的实际日期时间值为19年5月5日下午2:43:33,运行时显示的值为/Date(1557060213477)/ 预期结果显示数据库中存在的日期时间值 这是我的模型Javascript DataTables从数据库中呈现错误的DateTime值,javascript,c#,jquery,asp.net-mvc,datatables,Javascript,C#,Jquery,Asp.net Mvc,Datatables,我在asp.NETMVC项目中使用datatable插件,绑定数据时它会呈现错误的日期时间值 数据库中的实际日期时间值为19年5月5日下午2:43:33,运行时显示的值为/Date(1557060213477)/ 预期结果显示数据库中存在的日期时间值 这是我的模型 public int Id { get; set; } [Required] public string Name { get; set; } Display(Name ="Upload File")] public str
public int Id { get; set; }
[Required]
public string Name { get; set; }
Display(Name ="Upload File")]
public string FileUrl { get; set; }
public DateTime AddedOn { get; set; }
这是我的看法
<table id="DDR" class="table table-striped table-bordered dt-responsive nowrap">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Uploaded File</th>
<th>Uploaded At</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
</table>
@section scripts {
<link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
<script>
$(document).ready(function () {
debugger;
$("#DDR").DataTable({
"ajax": {
"url": "/DomesticDocRepositories/GetData",
"type": "GET",
"datatype": "json"
},
"columns": [
{
"data": "Id",
render: function (data, type) {
return '<a href="/DomesticDocRepositories/Details/' + data + '">'+data+"</a>";
}
},
{ "data": "Name" },
{
data: "FileUrl",
render: function (data, type) {
return "<a href='/DomesticFiles/" + data + " 'target='_blank''>" + data + "</a>";
}
},
{
"data": "AddedOn",
render: function (data, type) {
return '<span "title='+ data +"'>" + data +"</span>";
}
},
{
"render": function (data, type, full, meta) { return '<a class="btn btn-info" href="/DomesticDocRepositories/Edit/' + full.Id + '">Edit</a>'; }
},
{
data: null, render: function (data, type, row) {
return '<a class="btn btn-danger" href="/DomesticDocRepositories/Delete/' + row.Id + '">Delete</a>';
}
},
]
});
});
</script>
}
身份证件
名称
上传文件
上载于
编辑
删除
@节脚本{
$(文档).ready(函数(){
调试器;
$(“#DDR”).数据表({
“ajax”:{
“url”:“/DomesticDocRepositories/GetData”,
“类型”:“获取”,
“数据类型”:“json”
},
“栏目”:[
{
“数据”:“Id”,
呈现:函数(数据、类型){
返回';
}
},
{“数据”:“名称”},
{
数据:“文件URL”,
呈现:函数(数据、类型){
返回“”;
}
},
{
“数据”:“添加项”,
呈现:函数(数据、类型){
返回'use for datetimes()。在渲染中,应在渲染中使用:
{
render: function (data, type, row) {//data
return moment(row.AddedOn ).format('DD/MM/YYYY hh:mm:ss');//or another format you wantt.
}
}
用于datetimes()。在渲染中,应在渲染中使用:
{
render: function (data, type, row) {//data
return moment(row.AddedOn ).format('DD/MM/YYYY hh:mm:ss');//or another format you wantt.
}
}
未捕获引用错误:时刻未定义@hassansorry我忘了写moment.js
,我编辑了我的答案。未捕获引用错误:时刻未定义@hassansorry我忘了写moment.js
,我编辑了我的答案。