Editor - How to call from ASP.NET MVC?
Editor - How to call from ASP.NET MVC?
I used http://editor.datatables.net/manual/generator to build a sample for an ASP.NET Web API project. I can make an editable datatable using that.
But I need this to work in an ASP.NET MVC 5 View. This part of the JavaScript I use in the View:
$('#TSSRAvail').DataTable({
"dom": "Tfrtip",
"ajax": "/Home/EditData",
"columns": [ I PUT ALL THE COLUMNS HERE ][ // ,
});
does run. But using the IE Developer Toolbar Network tab, I see an Ajax request with a Type = "text/html". That does not call my server code in ""/Home/EditData".
I think I need the Ajax request to run as Type = "application/json". I would appreciate any help on this.
Replies
Hi,
You can add the contentType header to the Ajax request by using
ajax
in its object form:The object is passed directly through to
$.ajax
so you can use any of the jQuery options in it (apart fromsuccess
which should not be provided as DataTables uses that itself!).Allan
I changed the "ajax" part of the .DataTable(...) to:
Part of jqXHR contains these.NET error messages:
1. Description: HTTP 404. Please review the following URL and make sure that
it is spelled correctly.../Home/EditData
2. [HttpException]: A public action method 'EditData' was not found on controller
'TSSR.Controllers.HomeController'.
System.Web.Mvc.Controller.HandleUnknownAction(String actionName)
I don't know what settings I need on the .NET side.
I posted a similar question at http://forums.asp.net/p/2048602/5903654.aspx?Re+How+to+use+getJSON+in+MVC+5
Please check below link to see the full tutorial of Datatable.Net server side filtering, sorting, searching by using MVC.
http://blog.softtechsln.com/post/2015/05/06/mvc-and-datatable-net-1-10-server-side-paging-sorting-and-filtering
I deleted the attributes I had put above the ASP.NET MVC HomeController EditData method:
[System.Web.Mvc.HttpPost]
[System.Web.Mvc.HttpGet]
It seems that those in ASP.NET MVC mean ONLY allow that type of request. So the first one was blocking the ajax() GET call to "/Home/EditData".
I think you NEED both those above an ASP.NET Web API Controller method. You may want to note this in https://editor.datatables.net/manual/net/webapi, or any in ASP.NET samples you make.