Load ASP.Net MVC JSONResult jQuery DataTables

后端 未结 2 2029
暗喜
暗喜 2020-12-08 03:35

I\'m trying to get the DataTables(http://datatables.net) to work with a JsonResult returned by an ASP.Net MVC Controller. I keep getting a \"DataTables warning (table id = \

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 03:57

    In this example it appears that the data returned from the controller method needs to be in a specific format. He's actually returning the list as part of aaData. It also explains what each parameter is for. Perhaps you're just not formatting the return in a json format that DataTables understands.

    public class HomeController : Controller
    {
        public ActionResult AjaxHandler(jQueryDataTableParamModel param)
        {
            return Json(new{
                    sEcho = param.sEcho,
                    iTotalRecords = 97,
                    iTotalDisplayRecords = 3,
                    aaData = new List() {
                        new string[] {"1", "a1", "a2", "a3"},
                        new string[] {"2", "b1", "b2", "b3"},
                        new string[] {"3", "c1", "c2", "c3"}
                        }
                },
            JsonRequestBehavior.AllowGet);
        }
    }
    

提交回复
热议问题