Problem with server error handling on DataTables 1.10.9 with ASP.NET MVC 5
Problem with server error handling on DataTables 1.10.9 with ASP.NET MVC 5
edhalsim
Posts: 5Questions: 3Answers: 0
Hi,
My Datatables control is pulling rows from a server. The server may throw an exception as follows:
catch (Exception ex)
{
if (ex.Message.IndexOf("See the inner exception for details") > 0)
{
return Json(new { error = ex.InnerException.Message });
}
return Json(new { error = ex.Message });
}
I want to catch the error, not process the data as there isn't any, and show the error message on my page, preferable in the @Html.ValidationSummary() area. Here's what I have:
@section Scripts{
<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$.fn.dataTable.ext.errMode = 'none';
$('#search-results').on('error.dt', function(e, settings, techNote, message) {
console.log( 'An error has been reported by DataTables: ', message );
}).DataTable({
"processing": true,
"serverSide": true,
"searching": false,
"orderMulti": false,
"order": [[3, "asc"]],
"ajax": {
"url": "/providers/AjaxHandler",
"type": "POST",
"datatype": "json",
...
Problem is, nothing is getting logged. Even replacing "console.log" with a "debugger;" statement doesn't load the debugger.
Thanks for the help.
- Ed.
This discussion has been closed.
Answers
I found my initial error (JavaScript nesting). Now I'm getting this error:
Unable to get property 'ext' of undefined or null reference
on:
$.fn.dataTable.ext