将multidimentional数组从ajax传递到ASP.NET MVC

编程入门 行业动态 更新时间:2024-10-27 21:22:56
本文介绍了将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 angularjs

http 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

本文发布于:2023-11-25 01:30:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627762.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   ajax   multidimentional   MVC   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!