MD Islam

MD Islam

  • NA
  • 10
  • 810

pass multidimentional array from ajax to asp.net mvc

May 6 2018 7:20 AM
hello, I have tried to post json data from angularjs $http post to asp.net mvc controller here is json data example
  1. var postdata =  
  2.                {  
  3.   
  4.                   Email: "[email protected]",  
  5.                   selectedanswer: {0: 3, 1: 2, 2: 0, 3: 3, 4: 1}    
  6. };  
angular js code
  1. $http({  
  2.                 url: "/page/PostFileWithData",  
  3.                 headers: {  
  4.                     'Content-Type''application/json; charset=utf-8'  
  5.                 },  
  6.                 method: "POST",  
  7.                 dataType: "json",  
  8.                 traditional: true,  
  9.                 data: JSON.stringify(postdata)  
  10.             }).success(function (data) {  
  11.                 console.log(data);  
  12.             }).error(function (data) {  
  13.                 console.log('fail');  
  14.             });  
controller
  1. public JsonResult PostFileWithData(UserModel userdata)  
  2. {  
  3. UserModel udata = new UserModel  
  4. {  
  5. Email = userdata.Email  
  6. selectedanswer = userdata.selectedanswer  
  7. };  
  8. return Json(udata, JsonRequestBehavior.AllowGet);  
  9. }  
my Modal
  1. public class UserModel  
  2. {  
  3. public string Email { getset; }  
  4. public string selectedanswer { getset; }  
  5. }  
now problem is that I am getting email field ok in console.log but selectedanswer is null
 
like this
 
{Email: "[email protected]", selectedanswer: null}
 
can you please help me at this point?

Answers (1)