本文介绍了将multidimentional数组从ajax传递到ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hello, I have tried to post json data from angularjs $http post to asp mvc controller here is json data example var postdata = { Email: "test1@mail", selectedanswer: {0: 3, 1: 2, 2: 0, 3: 3, 4: 1} }; angular js code $http({ url: "/page/PostFileWithData", headers: { 'Content-Type': 'application/json; charset=utf-8' }, method: "POST", dataType: "json", traditional: true, data: JSON.stringify(postdata) }).success(function (data) { console.log(data); }).error(function (data) { console.log('fail'); }); controller public JsonResult PostFileWithData(UserModel userdata) { UserModel udata = new UserModel { Email = userdata.Email selectedanswer = userdata.selectedanswer }; return Json(udata, JsonRequestBehavior.AllowGet); } my Modal public class UserModel { public string Email { get; set; } public string selectedanswer { get; set; } } now problem is that I am getting email field ok in console.log but selectedanswer is null like this {Email: "test1@gmail", selectedanswer: null} can you please help me at this point?
我的尝试:
What I have tried:
hello, I have tried to post json data from angularjs $http post to asp mvc controller here is json data example var postdata = { Email: "test1@mail", selectedanswer: {0: 3, 1: 2, 2: 0, 3: 3, 4: 1} }; angular js code $http({ url: "/page/PostFileWithData", headers: { 'Content-Type': 'application/json; charset=utf-8' }, method: "POST", dataType: "json", traditional: true, data: JSON.stringify(postdata) }).success(function (data) { console.log(data); }).error(function (data) { console.log('fail'); }); controller public JsonResult PostFileWithData(UserModel userdata) { UserModel udata = new UserModel { Email = userdata.Email selectedanswer = userdata.selectedanswer }; return Json(udata, JsonRequestBehavior.AllowGet); } my Modal public class UserModel { public string Email { get; set; } public string selectedanswer { get; set; } } now problem is that I am getting email field ok in console.log but selectedanswer is null like this {Email: "test1@gmail", selectedanswer: null} can you please help me at this point?推荐答案
http发布到asp mvc控制器这里是json数据示例 var postdata = { 电子邮件:test1@mail, selectedanswer:{0:3,1:2,2:0,3:3,4: 1} }; angular js code http post to asp mvc controller here is json data example var postdata = { Email: "test1@mail", selectedanswer: {0: 3, 1: 2, 2: 0, 3: 3, 4: 1} }; angular js code
http({ url:/ page / PostFileWithData, header:{'Content-Type':'application / json; charset = utf-8'},方法:POST, dataType:json,传统:true,数据:JSON.stringify(postdata)})。success(函数(数据){ console.log(data); })。error( function(data){ console.log('fail'); }); controller public JsonResult PostFileWithData(UserModel userdata) { UserModel udata = new UserModel { Email = userdata .Email selectedanswer = userdata.selectedanswer }; 返回Json(udata,JsonRequestBehavior.AllowGet); } 我的模态 公共类UserModel { 公共字符串电子邮件{get;组; } public string selectedanswer {get;组; } } 现在的问题是我在console.log中收到电子邮件字段确定但是selectanswer是null 喜欢这个 {电子邮件:test1@gmail,selectedanswer:null} 你能不能请在这一点帮助我? http({ url: "/page/PostFileWithData", headers: { 'Content-Type': 'application/json; charset=utf-8' }, method: "POST", dataType: "json", traditional: true, data: JSON.stringify(postdata) }).success(function (data) { console.log(data); }).error(function (data) { console.log('fail'); }); controller public JsonResult PostFileWithData(UserModel userdata) { UserModel udata = new UserModel { Email = userdata.Email selectedanswer = userdata.selectedanswer }; return Json(udata, JsonRequestBehavior.AllowGet); } my Modal public class UserModel { public string Email { get; set; } public string selectedanswer { get; set; } } now problem is that I am getting email field ok in console.log but selectedanswer is null like this {Email: "test1@gmail", selectedanswer: null} can you please help me at this point?
我的尝试:
What I have tried:
hello, I have tried to post json data from angularjshttp post到asp mvc controller这里是json数据示例 var postdata = { 电子邮件:test1@mail, selectedanswer:{0:3,1:2,2:0,3 :3,4:1} }; angular js code http post to asp mvc controller here is json data example var postdata = { Email: "test1@mail", selectedanswer: {0: 3, 1: 2, 2: 0, 3: 3, 4: 1} }; angular js code
更多推荐
将multidimentional数组从ajax传递到ASP.NET MVC
发布评论