【问题标题】:Is this a valid jquery getJSON call?这是一个有效的 jquery getJSON 调用吗?
【发布时间】:2010-05-04 10:41:32
【问题描述】:

我正在使用 jquery getJSON 和 asp.net mvc 控制器......我无法让它工作......

 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

【问题讨论】:

    标签: jquery asp.net-mvc controller getjson


    【解决方案1】:

    通常,data 应该是一个对象:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 2016-11-24
      • 2010-11-25
      • 1970-01-01
      • 2017-09-30
      • 2020-07-01
      相关资源
      最近更新 更多