I want to send class as post ajax parameters.
my class :
public class PageInput
{
public string ActionName { get; set; }
public string Controller { get; set; }
public int CountPage { get; set; }
public int CountRecordInPage { get; set; }
public KeyValuePair<string, short> No { get; set; }
}
ajax code :
$.ajax({
url: '@Url.Action("GetPageNumbers", "MyClasses")',
data: '@Model.PageInput',
success: function (data) {
alert(data);
}
});
action :
public ActionResult GetPageNumbers(PageInput pageInput)
{
return PartialView("_PagingNumbers", pageInput);
}
doesn't working. But why?
When data are received by the actionResult are empty!!But the data are correct before sending.
You need to create an object within your JavaScript code and send that across instead:
$.ajax({
url: '@Url.Action("GetPageNumbers", "MyClasses")',
data: {
ActionName: '@Model.ActionName',
Controller: '@Model.Controller',
CountPage: @Model.CountPage,
CountRecordInPage: @Model.CountRecordInPage,
},
success: function (data) {
alert(data);
}
});
You also need to add the [HttpPost] attribute to your controller action
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With