Reputation: 1607
I am trying to pass a complex object to the controller through ajax Load(), however im getting a null object on the controller.
Ive seen some questions on this however they are on codeIgniter, I am using MVC.NET
Here's my code :
$('#btnLoadMore').on('click', function () {
dataObject.PageIndex = dataObject.PageIndex + 1;
$("#viewPlaceHolder").load("/home/GetPagedData",
{ data: JSON.stringify(dataObject), contentType: 'application/json', type: 'post' });
});
and this code below which is on the search click button is working fine.
$('#btnSubmit').on('click', function () {
var startDate = $('#StartDate').val();
var endDate = $('#EndDate').val();
dataObject= {
'UserId': 1,
'PageIndex': pageIndex,
'PageSize': pageSize,
'StartDate': startDate,
'EndDate': endDate
};
$.ajax({
url: '@Url.Action("GetPagedData", "Home")',
contentType: 'application/json',
type: 'post',
cache: false,
async: true,
data: JSON.stringify(dataObject)
,
success: function (result) {
$('#pricing-table').html(result);
window.location = "#pricing";
}
});
});
Upvotes: 0
Views: 1419
Reputation: 8539
From jQuery Load article:
The POST method is used if data is provided as an object; otherwise, GET is assumed.
You can provide in load
method only url, data, complete callback parameters.
So your code should looks like this:
$('#btnLoadMore').on('click', function () {
dataObject.PageIndex = dataObject.PageIndex + 1;
$("#viewPlaceHolder").load("@Url.Action("GetPagedData","Home")",
dataObject);
});
Upvotes: 3