如何在mvc4中使用json查看arraylist项目控制器 [英] how to arraylist item controller to view using json in mvc4

查看:69
本文介绍了如何在mvc4中使用json查看arraylist项目控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我希望传递arraylist数据控制器使用json查看。

我的代码如下: -





我的控制器代码: -



sir i want pass arraylist data controller to view using json.
my code following:-


My controller Code:-

public JsonResult LoadChild()
        {
            DataTable dt = new DataTable();
            SqlConnection con = new          SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
            string qry1 = "Select * from tbTest";
            SqlCommand cmd = new SqlCommand(qry1,con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            
            ArrayList list3 = new ArrayList();
            foreach (DataColumn dr2 in dt.Columns) // dt- DataTable
            {
                list3.Add(dr2);

                
            }
            return Json(list3, JsonRequestBehavior.AllowGet);
        }





我的浏览页面代码: -





My view page code:-

<script>
function LoadChild()
    {
        $(document).ready(function ()
        {
            $.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    url: "/AddModule/LoadChild",
                    data: {},
                   dataType: "json",
                     success: function (data)
                    {
                       
                        alert(data); 
                     
                       
                    },
                    error: function (result) {
                        alert("hello Error");
                    }
                });
            });
    }
</script>

推荐答案

document )。ready( function ()
{
(document).ready(function () {


.ajax({
type : GET
contentType: application / json; charset = utf-8
url: / AddModule / LoadChild
data:{},
dataType: json
成功:功能(数据)
{

提醒(数据);


},
错误: function (结果){
alert( hello Error);
}
});
});
}
< / script>
.ajax({ type: "GET", contentType: "application/json; charset=utf-8", url: "/AddModule/LoadChild", data: {}, dataType: "json", success: function (data) { alert(data); }, error: function (result) { alert("hello Error"); } }); }); } </script>


这篇关于如何在mvc4中使用json查看arraylist项目控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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