2010-05-04 18 views
3

我使用jQuery的getJSON与asp.net的MVC控制器......我不能能得到它的工作....这是一个有效的jQuery getJSON调用?

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

和我与调用此,

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

该调用似乎没有工作....

通过萤火检查时,我发现这个,

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

通常,data应的对象:

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

@Kobi雅错过了''{..感谢了Kobi .. – 2010-05-04 10:46:35