Jquery返回undefined

时间:2018-02-25 11:02:22

标签: javascript jquery asp.net-mvc

我正在使用带有EF6的ASP.NET MVC。在Ajax调用搜索时,each()方法返回undefined,尽管每个数组的length都是正确的。

 $.ajax({
   type: "GET",
   url: "something",
   contentType: "html",
   success: function (result) {
     //Receive the filtering data from controller and show it for user
     SetData.append('<p>' + result.length+'</p>') //It's working correctly
     $.each(result, function (index, value) {
       var Data = "<p>" + value.supervisorName + "</p>"; // return undefined 
       console.log(value.supervisorName) //also return undefined
       SetData.append(Data);
     });
   }
});

controller方法

public JsonResult GetSearchingData(string SearchBy, string SearchValue)
     {
        Entities5 db = new Entities5();
        List<Supervisors> StuList = new List<Supervisors>();
        StuList = db.Supervisors.Where(x => x.supervisorName.StartsWith(SearchValue) || SearchValue == null).ToList();
        var subCategoryToReturn = StuList.Select(S => new { Name = S.supervisorName });
        return Json(subCategoryToReturn, JsonRequestBehavior.AllowGet);

     }

1 个答案:

答案 0 :(得分:0)

将Name更改为supervisorName

后,它正在工作
var subCategoryToReturn = StuList.Select(S => new { supervisorName = S.supervisorName });