Member 12874872 Ответов: 0

Передача многомерного массива из 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? 


Что я уже пробовал:

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? 

Kornfeld Eliyahu Peter

Проблема в том, что selectedanswer-это не строка...

0 Ответов