Passing custom http variables to serverside ASP .Net MVC
Passing custom http variables to serverside ASP .Net MVC
jimkiely
Posts: 9Questions: 10Answers: 0
I posted this question on stackoverflow but it was not answered.
http://stackoverflow.com/questions/25271717/datatable-js-ajax-pass-variable-to-c-sharp-serverside-method
I'm trying to pass parameters to the serverside and I can not get it to work. I looked at the custom http variables example and I can not get the variables to show up on the serverside.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Are you trying to retrieve information from the table to send to the server side method after initialization?
I need to pass information in dropdownlists and all the paging, sorting, info.
.
There is a way to do this with the normal Ajax call but I came across all sorts of issues I didn't like. Datatables give you the facility to make your own Ajax call which is now how I do It. Note that this method will only pass parameters YOU now specify. In this example I dont pass any of the built in Datatables search etc as I dont use them.
Also see http://datatables.net/examples/server_side/custom_vars.html
wjhumphreys,
This worked great expect that the paging is not working correctly. I'm handling the paging on the serverside but paging information below the table is not getting populated correctly.
"Showing 0 to 0 of 0 entries (filtered from NaN total entries)" and the number of Pages is inaccurate.
I'm so new to this so. Can I make an ajax call with variables and allow the sorting and paging to be handled clientside? Or should I handle everthing serverside and pass back paging data so that datables knows how to handle it?
Here's the code:
var tblSpecification = $('#tblSpecification').DataTable({
"serverSide": true,
"ajax": function (data, callback, settings) { // Make the Ajax call ourselves
$.ajax({
url: "../../Search/Specification",
type: "POST",
dataType: "json",
data: {
draw: data.draw, // Needed for paging
start: data.start, // Needed for paging
length: data.length, // Needed for paging
compareType: $('#ddlComparison').val(),
specData: $('#ddlSpecData').val(),
specData2: $('#ddlSpecData2').val(),
specType: $('#ddlSpecType').val(),
partType: $('#ddlPartType').val(),
},
beforeSend: function (xhrObj) {
// Whatever
}
})
.done(function (data, textStatus, jqXHR) {
Nevermind! I removed the serverside and i'm using ajax.reload whenever I need to grab new data.