mvc2中的数据表无法正常工作 [英] datatable in mvc2 not working

查看:75
本文介绍了mvc2中的数据表无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的观点

Here is my View

<script>
    function filltable() {
        alert("in other method");
        window.oTable = $("#table").dataTable({
            "bServerSide": true,
            "sAjaxSource": "Url.Action(User/GetResult)",
            "sAjaxDataProp": "aaData",
            "aoColumns": [
                { "mDataProp": "USER_NAME" },
                { "mDataProp": "EMAIL_ID" },
                { "mDataProp": "MOBILE_NO" }
            ],
            "bJQueryUI": true,
            "bProcessing": false
        });
    }
</script>





为什么sAjaxSource不会重定向到网址?请帮忙...



更新





Why sAjaxSource doesn't redirect to the url? Please help...

UPDATE

Now it is rediecting to Url.bt it doesnt show data which is coming from controller in this format in mvc2---->

{[
  {
    "USER_NAME": "alpa",
    "MOBILE_NO": "000",
    "EMAIL_ID": "alpa.sae",
    "COLOR_NAME": "Red",
    "COLOR_ID": 0
  },
  {
    "USER_NAME": "alpas",
    "MOBILE_NO": "000",
    "EMAIL_ID": "alpa.sae",
    "COLOR_NAME": "Green",
    "COLOR_ID": 0
  }
]}


My controller



[HttpGet]
        public JsonResult GetResult()
        {
            JArray JsonArray = new JArray();
            JObject jo = new JObject();

            
             
            List plist = new List();
            User tUser = new User();
           
            tUser.USER_NAME = "alpa";
            tUser.EMAIL_ID = "alpa.sae";
            tUser.MOBILE_NO = "000";
            tUser.COLOR_NAME = "Red";
            plist.Add(tUser);

            tUser = new User();
            tUser.USER_NAME = "alpas";
            tUser.EMAIL_ID = "alpa.sae";
            tUser.MOBILE_NO = "000";
            tUser.COLOR_NAME = "Green";
            plist.Add(tUser);

            JsonArray = (JArray)JToken.FromObject(plist);

            jo["Message"] = "Data Saved Succeffully";
            jo["data"] = JsonArray;
           // return Json(plist, JsonRequestBehavior.AllowGet);
            var aaData = new Response(true, "Contact Successfully Submitted", jo["data"].ToString());
            return Json(aaData);
        }
  }

推荐答案

#table)。dataTable({
bServerSide true
sAjaxSource Url.Action(User / GetResult)
sAjaxDataProp aaData
aoColumns:[
{ mDataProp USER_NAME},
{ mDataProp EMAIL_ID},
{ mDataProp MOBILE_NO}
],
bJQueryUI true
b处理 false
});
}
< / script>
("#table").dataTable({ "bServerSide": true, "sAjaxSource": "Url.Action(User/GetResult)", "sAjaxDataProp": "aaData", "aoColumns": [ { "mDataProp": "USER_NAME" }, { "mDataProp": "EMAIL_ID" }, { "mDataProp": "MOBILE_NO" } ], "bJQueryUI": true, "bProcessing": false }); } </script>





为什么sAjaxSource不会重定向到网址?请帮忙...



更新





Why sAjaxSource doesn't redirect to the url? Please help...

UPDATE

Now it is rediecting to Url.bt it doesnt show data which is coming from controller in this format in mvc2---->

{[
  {
    "USER_NAME": "alpa",
    "MOBILE_NO": "000",
    "EMAIL_ID": "alpa.sae",
    "COLOR_NAME": "Red",
    "COLOR_ID": 0
  },
  {
    "USER_NAME": "alpas",
    "MOBILE_NO": "000",
    "EMAIL_ID": "alpa.sae",
    "COLOR_NAME": "Green",
    "COLOR_ID": 0
  }
]}


My controller



[HttpGet]
        public JsonResult GetResult()
        {
            JArray JsonArray = new JArray();
            JObject jo = new JObject();

            
             
            List plist = new List();
            User tUser = new User();
           
            tUser.USER_NAME = "alpa";
            tUser.EMAIL_ID = "alpa.sae";
            tUser.MOBILE_NO = "000";
            tUser.COLOR_NAME = "Red";
            plist.Add(tUser);

            tUser = new User();
            tUser.USER_NAME = "alpas";
            tUser.EMAIL_ID = "alpa.sae";
            tUser.MOBILE_NO = "000";
            tUser.COLOR_NAME = "Green";
            plist.Add(tUser);

            JsonArray = (JArray)JToken.FromObject(plist);

            jo["Message"] = "Data Saved Succeffully";
            jo["data"] = JsonArray;
           // return Json(plist, JsonRequestBehavior.AllowGet);
            var aaData = new Response(true, "Contact Successfully Submitted", jo["data"].ToString());
            return Json(aaData);
        }
  }


请尝试如下。



Please try is as below.

[HttpGet]
public JsonResult GetResult()
{

    //Your code here

    return Json(aaData,JsonRequestBehavior.AllowGet);
}


这篇关于mvc2中的数据表无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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