views:

86

answers:

1

I am using jquery getJSON with asp.net mvc controller... I cant able to get it 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 am calling this with,

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

This call doesn't seem to work....

when inspected 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
+2  A: 

Typically, data should be an object:

$.getJSON('Materials/GetMaterials', {'currentPage':1,'pageSize':5},
 function(data) {
    });
Kobi
@Kobi ya missed that `{`.. Thanks Kobi..
Pandiya Chendur