Вы должны вернуть JsonResult
с произвольным объектом (или реальный объект, если вы создали один) соответствие ожидаемого возврата подписи для DataTables. Что-то вроде:
var result = // do something, get a list of stuff etc
return new JsonResult {
// `Data` is the thing that turns into your json response
Data = new {
error = result.Success ? "" : result.Message,
fieldErrors = new bool[0], // just to fake an empty array
data = new bool[0],
aaData = result.Success ? result.Items.Select(o => new {
//use arbitrary column names if you've specified them in config with `aoColumns` and `mDataProp`, see comment below
OrderID = o.ID,
ChannelID = o.Partner,
ReferenceKey = o.PartnerReferenceKey,
o.CustomerEmail,
Status = o.Status.ToString(),
Value = o.Total,
CreatedOn = o.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss"), // provide in interpretable format
}) : (object) new bool[0], // must return an empty list in order for it to understand errors
iTotalRecords = result.TotalCount,
iTotalDisplayRecords = result.TotalCount, // should be different if filtering
sEcho // this is provided by the request, not sure what it means...
}
};
Для пользовательских имен столбцов из ответа Ajax, вы хотите просмотреть:
Но я использую DataTable, так что не aceeptable – user279stack
мы используем таблицу данных jauery на стороне клиента, нам нужно только отправить ошибку в datatable formate – user279stack