【发布时间】:2016-05-05 16:01:15
【问题描述】:
我正在使用 mongoDB 作为数据库和数据表来构建 Web 应用程序来处理我的表。 我的问题是,在渲染过程中,我得到了 [object object] 而不是从 mongodb 检索中获取 ObjectID。
所以在 html 中我有这个代码:
var t = $("#general-table-list").DataTable({
sAjaxSource: "/AccountCategories/Get",
"bFilter": false,
"deferLoading": 0,
"columnDefs": [
{
'targets': 2,
'searchable': false,
'orderable': true,
'className': 'dt-body-center',
'render': function (data, type, full, meta) {
return '<a href="/AccountCategories/Details/' + full.Id.toString() + '" class="btn btn-info"><span class="fa fa-edit"></span> Edit</a> ';
}
}],
"select": [
{
"style" : "os",
"selector": "td:first-child"
}
],
"columns": [
{ "data": null, "orderable": false },
{ "data": "Name", "orderable": false },
{ "data": "Action", "orderable": false }
],
"order": [],
})
t.on('order.dt search.dt', function () {
t.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
我如何获取数据:
public JsonResult Get(DataTableParameters param)
{
var data = _helper.GetData(param);
return Json(data, JsonRequestBehavior.AllowGet);
}
下面是截图:
这是在 UI 上呈现的内容:
我该如何解决这个问题?感谢任何帮助
==== 更新 ====
我设法通过更改 ID 来解决这个问题 来自:
[BsonId]
public ObjectId Id { get; set; }
到:
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
【问题讨论】:
标签: c# ajax mongodb datatables