将multidimentional数组从ajax传递到ASP.NET MVC [英] Pass multidimentional array from ajax to ASP.NET MVC

查看:61
本文介绍了将multidimentional数组从ajax传递到ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hello, I have tried to post json data from angularjs $http post to asp.net mvc controller here is json data example
 
 
 var postdata =
                                 {

                                     Email: "test1@mail.com",
                                     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.com", 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.net mvc controller here is json data example
 
 
 var postdata =
                                 {

                                     Email: "test1@mail.com",
                                     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.com", selectedanswer: null} 
 
 
can you please help me at this point? 

推荐答案

http发布到asp.net mvc控制器这里是json数据示例


var postdata =
{

电子邮件:test1@mail.com,
selectedanswer:{0:3,1:2,2:0,3:3,4: 1}
};


angular js code
http post to asp.net mvc controller here is json data example var postdata = { Email: "test1@mail.com", 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.com,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.com", 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.net mvc controller这里是json数据示例


var postdata =
{

电子邮件:test1@mail.com,
selectedanswer:{0:3,1:2,2:0,3 :3,4:1}
};


angular js code
http post to asp.net mvc controller here is json data example var postdata = { Email: "test1@mail.com", selectedanswer: {0: 3, 1: 2, 2: 0, 3: 3, 4: 1} }; angular js code


这篇关于将multidimentional数组从ajax传递到ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆