zoukankan      html  css  js  c++  java
  • Asp.Net MVC2 Json

    View层-->View层的JS function-->Controller-->返回JSON数据-->View层的JS function

    Controller:

            public ActionResult JsonHashTable()
            {

                ArrayList list = new ArrayList();
                Hashtable ht1 = new Hashtable();
                Hashtable ht2 = new Hashtable();

                ht1.Add("Key""value11");
                ht2.Add("Key""value222");
                list.Add(ht1);
                list.Add(ht2);

                return Json(list, JsonRequestBehavior.AllowGet);
            }

            public ActionResult JsonModel()
            {
                ChangePasswordModel model = new ChangePasswordModel();
                model.NewPassword = "gxw";
                return Json(model, JsonRequestBehavior.AllowGet);
            }

    View层:

        <script type="text/javascript">
            
    function getHashTable() {
                $.getJSON(
    "/home/JsonHashTable"function (da) {
                    alert(da.length);
                });
            }
            
    function getModel() {
                $.getJSON(
    "/home/JsonModel"function (da) {
                    alert(da.NewPassword);
                });
            }
        
    </script>

        <input type="button" id="btn" value="HashTable" onclick="getHashTable()" />
        <input type="button" id="Button1" value="Model" onclick="getModel()" />

    当我们进入index.aspx页面后,出现两个button按钮,点击HashTable就调用getHashTable函数,这个函数访问Controller层JsonHashTable(),获得JSON,然后返回给前台View层

  • 相关阅读:
    nginx 详解--概念解释以及配置---转载
    jmeter和loadrunner测试结果差异大-web页面静态资源下载--转载
    一、性能测试的八大类--转载
    fiddler学习总结--手机端(APP/微信小程序)抓包--转载
    HTTP协议详解(真的很经典)--转载
    oracle修改表名和列名的多种方式
    LR web_custom_request
    web_add_cookie()
    Linux tar命令
    Linux下zip与unzip命令使用详解
  • 原文地址:https://www.cnblogs.com/bingzisky/p/2184861.html
Copyright © 2011-2022 走看看