Я видел этот вопрос: Ошибка Jatery Datatables: недопустимый примитив JSON: draw
Это не может помочь мне решить проблему.
Я использую Datatables,Я получаю сообщение об ошибке для вызова AJAX.Вот код JS:
function loadparttrackings() {
// Call the datatable on the overview div and link back to server side
$('#overviewFilteredPartTrackings').DataTable({
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"ajax": {
"url": window.applicationPath + "/Launches/GetFilteredPartTrackingRecords",
"type": "POST",
"data": function (d) {
d.partNumber = $('#FilterPartNumber').val();
d.segment = $('#FilterSegment').val();
d.commodity = $('#FilterCommodity').val();
}
},
// This is needed to hide the ID field and make it not searchable
"columnDefs":
[{
"targets": [1],
"visible": false,
"searchable": false
}],
"columns": [
{
"render": function (data, type, full, meta) { return '<a class="btn btn-info" href="#" onclick=EditRecord("' + row.ID + '"); >Edit</a>'; }
},
// more columns omitted
});
}
Проблема возникла, когда я добавил "type": "POST",
в AJAX-часть функции.Теперь я получаю ошибку invalid json primitive draw
.
Вот код для метода контроллера:
[HttpPost]
public ActionResult GetFilteredPartTrackingRecords(DataTableAjaxPostModel model, string partNumber, string commodity, string segment)
{
// Getting the data and such
return Json(new
{
// this is what datatables wants sending back
draw = model.draw,
recordsTotal = 1000, // TODO CHANGE
recordsFiltered = 1000, // TODO CHANGE
data = result
});
}
А вот код для модели, которую я использую:
public class DataTableAjaxPostModel
{
// properties are not capital due to json mapping
public int draw { get; set; }
public int start { get; set; }
public int length { get; set; }
public List<Column> columns { get; set; }
public Search search { get; set; }
public List<Order> order { get; set; }
}
public class Column
{
public string data { get; set; }
public string name { get; set; }
public bool searchable { get; set; }
public bool orderable { get; set; }
public Search search { get; set; }
}
public class Search
{
public string value { get; set; }
public string regex { get; set; }
}
public class Order
{
public int column { get; set; }
public string dir { get; set; }
}