再谈Jquery Ajax方法传递到action
来源:互联网 发布:达内linux视频 百度云 编辑:程序博客网 时间:2024/06/04 18:20
- public ActionResult ReadPerson(PersonModel model)
- {
- string s = model.ToString();
- return Content(s);
- }
- public ActionResult ReadPersons(List<PersonModel> model)
- {
- string result = "";
- if (model == null) return Content(result);
- foreach (var s in model)
- {
- result += s.ToString();
- result += "-------------";
- }
- return Content(result);
- }
- public class PersonModel
- {
- public int id
- {
- set;
- get;
- }
- public string name
- {
- set;
- get;
- }
- public int age
- {
- set;
- get;
- }
- public bool gender
- {
- set;
- get;
- }
- public string city
- {
- set;
- get;
- }
- public override string ToString()
- {
- string s = string.Format(@"id:{0}
- name:{1}
- age:{2}
- gender:{3}
- city:{4}
- ", id, name, age, gender, city);
- return s;
- }
- }
- var person = {
- id: "001",
- name: "zhangsan",
- age: "20",
- gender: true,
- city: "shanghai"
- };
- var option = {
- url: '/test/ReadPerson',
- type: 'POST',
- data: person,
- dataType: 'html',
- success: function (result) { alert(result); }
- };
- $.ajax(option);
- var option = {
- url: '/test/ReadPerson',
- type: 'POST',
- data: JSON.stringify(person),
- dataType: 'html',
- success: function (result) { alert(result); }
- };
- $.ajax(option);
- var option = {
- url: '/test/ReadPerson',
- type: 'POST',
- data: person,
- dataType: 'html',
- contentType: 'application/json',
- success: function (result) { alert(result); }
- };
- var option = {
- url: '/test/ReadPerson',
- type: 'POST',
- data:JSON.stringify(person),
- dataType: 'html',
- contentType: 'application/json',
- success: function (result) { alert(result); }
- };
- var persons = [{
- id: "001",
- name: "zhangsan",
- age: "20",
- gender: true,
- city: "shanghai"
- },
- {
- id: "002",
- name: "lisi",
- age: "21",
- gender: false,
- city: "beijing"
- }
- ];
- var jsonp = { model: persons };
- var option = {
- url: '/test/ReadPersons',
- type: 'POST',
- data: jsonp,
- dataType: 'html',
- success: function (result) { alert(result); }
- };
- var option = {
- url: '/test/ReadPersons',
- type: 'POST',
- data: JSON.stringify(jsonp),
- dataType: 'html',
- success: function (result) { alert(result); }
- };
- var option = {
- url: '/test/ReadPersons',
- type: 'POST',
- data: jsonp,
- dataType: 'html',
- contentType: 'application/json',
- success: function (result) { alert(result); }
- };
- var option = {
- url: '/test/ReadPersons',
- type: 'POST',
- data: JSON.stringify(persons),
- dataType: 'html',
- contentType: 'application/json',
- success: function (result) { alert(result); }
- };
- public ActionResult Fortest(TestClassB TB,List<TestClassA> TA)
- {
- string result = "";
- return Content(result);
- }
- public class TestClassA
- {
- public string a1 { set; get; }
- public List<string> a2 { set; get; }
- }
- public class TestClassB
- {
- public string b1 { set; get; }
- public InnerTestClassC ITCC { set; get; }
- public class InnerTestClassC
- {
- public List<int> c1 { set; get; }
- }
- }
- $("#btn").click(function () {
- var jsondata = { TB: {}, TA: [] };
- jsondata.TB.b1 = "b1";
- jsondata.TB.ITCC = {};
- jsondata.TB.ITCC.c1 = new Array(1, 2, 3, 4);
- var ta1 = {};
- ta1.a1 = "a1";
- ta1.a2 = new Array("a", "b", "x", "y");
- var ta2 = {};
- ta2.a1 = "a2";
- ta2.a2 = new Array("a2", "b2", "x2");
- jsondata.TA.push(ta1);
- jsondata.TA.push(ta2);
- var option = {
- url: '/test/Fortest',
- type: 'POST',
- data: JSON.stringify(jsondata),
- dataType: 'html',
- contentType: 'application/json',
- success: function (result) { alert(result); }
- };
- $.ajax(option);
- });
0 0
- 再谈Jquery Ajax方法传递到action
- 再谈Jquery Ajax方法传递到action
- 再谈Jquery Ajax方法传递到action
- 再谈Jquery Ajax方法传递到action
- Jquery Ajax方法传递到action
- .NET MVC 再谈Jquery Ajax方法传递到action
- easyui-ajax表单和jquery-ajax传递参数 到 Action(后台)
- ssh 中 jquery ajax 调用action返回的json数据并传递到页面
- Jquery Ajax方法传值到action的方法
- .NET MVC Jquery Ajax方法传值到action
- jquery ajax像后台action中传递数组
- jquery ajax 调用mvc action传递复杂参数
- 传递参数的标准方法(jQuery.ajax)
- Jquery ajax 从action中传多个参数到js里面使用
- Struts2 get方法传递 中文 到Action乱码解决
- jsp页面传递参数到action中的几种方法
- jquery ajax json struts2 action中的方法执行了两次
- jquery中使用ajax传递数组到webservice
- qt中实现QDoubleSlider
- 移动端重构系列2——新建空白页面
- POJ 2386 Lake Counting (dfs)
- 北京人文大学清华IT成才典礼
- 连接两个字面值常量并输出
- 再谈Jquery Ajax方法传递到action
- Java 8 的日期时间新用法
- 小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载四(场景切换)
- hdu 4869 组合数
- selenium API中文
- 二维码扫描,中文解释源码
- MPEG-4视频压缩基础
- 2015上海华交会
- 怎样使用Gson 解析 (deserialize) json字符串