首页 > 代码库 > MVC视图中处理Json

MVC视图中处理Json

/// <summary>        /// 登录        /// </summary>        /// <param name="value"></param>        /// <returns></returns>        public JsonResult Login()        {            List<FACTORY> userList = new List<FACTORY>            {              new FACTORY{FACTORY_NAME="zzl",FACTORY_CODE="bfyxzls@sina.com"},
new FACTORY{FACTORY_NAME="zhz",FACTORY_CODE="zhanghangzheng@sina.com"}, };
JsonResult json = new JsonResult
{
Data = http://www.mamicode.com/userList
};
return Json(json); }
 

//return Json(json, JsonRequestBehavior.AllowGet);//前台AJAX如果是GET用这句

//什么时候用GET请求呢,当我们直接在浏览器中输入网址时,其实就是一个GET请求

//如果我们直接输入/Home/TestList这个网址,它会提示我们下载这个JSON格式的文档

  

 

 $(function () {        $("#Get").click(function () {            $.ajax({                type: "POST",                contentType: "application/json",                url: "Test/Login",                              dataType: ‘json‘,                success: function (result) {                    var msg = "<table border=1px><tr><td>Name</td><td>Code</td></tr>";                    for (var i = 0, length = result.rows.length; i < length;i++)                    {                        //alert(result.rows[i]["FACTORY_NAME"]);                        msg += "<tr><td>" + result.rows[i]["FACTORY_NAME"] + "</td><td>" + result.rows[i]["FACTORY_CODE"] + "</td></tr>";                    }                    msg += "</table>";                    $("#msg2").html(msg);                }            });        });    });

  

 

MVC视图中处理Json