ASP.NET 后台获取backbone提交的数据

来源:互联网 发布:逆战原子0.19秒宏数据 编辑:程序博客网 时间:2024/06/16 03:12

前端代码

<script>        // 定义studentModel        var student = Backbone.Model.extend({            initialize:function(){},            url:"Handler1.ashx",            defaults:{                Code:"100",                Name:"user"            }                    });        // 实例化        var stu = new student();        // 向服务器提交数据        stu.save(null, {            success: function (model, response) {                alert(response);            }        });    </script>

后台代码

public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";                        // 获取前端提交的json字符串            var strJson = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd();                        // 将json反序列化到Stu            JavaScriptSerializer js = new JavaScriptSerializer();            Stu sn = js.Deserialize<Stu>(strJson);              context.Response.Write(sn.Name);        }        public class Stu        {            public int ID            {                set;                get;            }            public string Code            {                set;                get;            }            public string Name            {                set;                get;            }        }


0 0
原创粉丝点击