如何处理<> f__AnonymousType0`2 [System.Int32,System.String] []? [英] how can I handle <>f__AnonymousType0`2[System.Int32,System.String][]?

查看:50
本文介绍了如何处理<> f__AnonymousType0`2 [System.Int32,System.String] []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问从方法返回的列表.

I want to access a List which I return from method.

但是我遇到了错误

未捕获的TypeError:无法读取未定义的属性'length',

Uncaught TypeError : Cannot read property 'length' of undefined,

当我调试代码时,我在变量结果中得到了返回值,例如<> f__AnonymousType0`2 [System.Int32,System.String] [] ,所以我该如何处理和使用返回值我从方法中返回了哪一个?

when I debug my code I got return value in Variable result like <>f__AnonymousType0`2[System.Int32,System.String][], so how can I handle and use return value which I have returned from method?

$('#DTAttendance tbody').on('click', 'tr', function () {
     var aData = oTable.fnGetData(this);
     var lectureid = aData[0];
     $.ajax({
         type: "POST",
         url: '@Url.Action("GetStudentList", "Attendance")',
         contentType: "application/json; charser=utf-8",
         data: JSON.stringify({ 'lectureid': lectureid }),
         success: function (result) {
            if (result != 0) {
              var dynhtml = "";
              $.each(result.allrecord, function (i, item) {
                dynhtml += "<tr><td>" + item.sid + "<td><td>" + item.sname + "<td></tr>"
            });
            dynhtml = "<table>" + dynhtml + "</table>";
            $("#dttable").html(dynhtml);
           }
          else {
            alert("Some error");
               }
           }
    });
  });
}

GetStudentList函数

GetStudentList Function

 [HttpPost]
 public object GetStudentList(Int32 lectureid)
   {
    try
      {
        object allrecord = _IAcademy_Repository.GetStudentRecordAccordingAttendanceWise(lectureid);
        return allrecord;
      }
    catch (Exception ex)
      {
        Console.WriteLine("\nMessage ---\n{0}", ex.Message);
        return 0;
      }
    }

推荐答案

将其放在您的控制器端

[HttpPost]
        public object GetStudentList(Int32 lectureid)
        {
            try
            {
                object allrecord = _IAcademy_Repository.GetStudentRecordAccordingAttendanceWise(lectureid);
                return Json(allrecord);
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nMessage ---\n{0}", ex.Message);

                return 0;

            }
        }


// And You Should Place 



$.each(result, function (i, item) {
                            dynhtml += "<tr><td>" + item.sid + "<td><td>" + item.sname + "<td></tr>"
                        });

这篇关于如何处理&lt;&gt; f__AnonymousType0`2 [System.Int32,System.String] []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆