Sagar
Sagar

Reputation: 292

How can i pass list of array in angular js?

I am using restangular post method to send my JSON to Web API. At console window i can see the $scope.school is getting populated with the details but at web API i am not getting 'fileSet' object values.

My angular code is: -

      $scope.school = {
            'class': '94E38941-5A97-4A9B-B82A-8D53C9DBEE96',
            'inputInstanceId': 'CBBCD28D-F144-45E2-A494-C767549BD3AF',
            'inboxType': '8',
            'schoolTitle': $scope.value1,
            'schoolDescription': $scope.value2,
            'schoolContext': $scope.ContextListL1["Value"],
            'schoolGuid ': $cookieStore.get('objschoolid'),
            'fileSet': {
                'fName': fileName,
                'fileUploadId': fileId
            }
        }

where as my api calling code in angular is

 Restangular.one(routeString).post('', $scope.school, params, headers).then(function (resp)

My API class is

public class CreateClassDTO
{
    public Guid class { get; set; }
    public Guid inputInstanceId { get; set; }
    public int inboxType { get; set; }
    public string schoolTitle { get; set; }
    public string schoolDescription { get; set; }
    public string schoolContext { get; set; }
    public Guid schoolGuid { get; set; }
    public List<FileuploadResult> fileSet { get; set; }

}

public class FileuploadResult
{
    public string fName { get; set; }
    public Guid fileUploadId { get; set; }
}

Upvotes: 0

Views: 235

Answers (3)

Pandi_Snkl
Pandi_Snkl

Reputation: 494

You can Do objects inside the Object. Like this example

In Mvc

public class Userplusresponse
{
    public User user { get; set; }
    public string response { get; set; }
}



public class User
    { 
    public string username{get; set;}
    public string firstName { get; set; }
    public string LastName { get; set; }
    public string password { get; set; }
    public string con_password { get; set; }    
    public int phoneNumber { get; set; }
    }

And Angular or Ajax Post

 $scope.User = {}; //**Add more values
 var dataplusresponse = {}
                dataplusresponse.user = User;
                dataplusresponse.response = response;

 $http({
                    method: 'POST',
                    url: '@Url.Action("Register", "Account")',
                    data: dataplusresponse, //forms user object
                    headers: { 'Content-Type': "application/json" }
                })
          .success(function (data) {

              console.log(data);
}

And Controller

[HttpPost]
        public ActionResult Register(Userplusresponse UR)
        {
            var captchaResponse = UR.response;  //this is object of response

            var UserData = UR.user;  //this is object of $scope.user
//You can get child object from UserData

Upvotes: 0

Thorsten
Thorsten

Reputation: 91

You are referencing two variables in the fileset

'fileSet': {
    'fName': fileName,
    'fileUploadId': fileId
}

namely fileName and fileId. Are these variables defined?

Upvotes: 0

Ankh
Ankh

Reputation: 5718

I'm going to assume that fileSet should be an array of objects rather than a single object:

'fileSet': [
    {
        'fName': fileName,
        'fileUploadId': fileId
    }
]

Upvotes: 2

Related Questions