Is this a valid jQuery getJSON call?

I am using jquery getJSON with an asp.net mvc controller ... I cannot get it to work.

 public JsonResult GetMaterials(int currentPage,int pageSize)
 {
   var materials = consRepository.FindAllMaterials().AsQueryable();
   var results = new PagedList<MaterialsObj>(materials, currentPage-1, pageSize);
   return Json(results);
 }

and I call it with

$.getJSON('Materials/GetMaterials', "{'currentPage':1,'pageSize':5}",
 function(data) {
    });

This call does not work.

when checking through firebug I found this,

The parameters dictionary contains a null entry for parameter 
'currentPage' of non-nullable type 'System.Int32' for method 
'System.Web.Mvc.JsonResult GetMaterials(Int32, Int32)' in 
'CrMVC.Controllers.MaterialsController'. To make a parameter optional its type
 should be either a reference type or a Nullable type.<br>
 Parameter name: parameters
+3
source share
1 answer

Usually datashould be an object:

$.getJSON('Materials/GetMaterials', {'currentPage':1,'pageSize':5},
 function(data) {
    });
+2
source

Source: https://habr.com/ru/post/1743963/


All Articles