0

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; }
}

3 Answers 3

2

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

'fileSet': [
    {
        'fName': fileName,
        'fileUploadId': fileId
    }
]
Sign up to request clarification or add additional context in comments.

2 Comments

Yes exactly as you can see in my class structure it is a list object
No, it did not work for me, still at my api i am getting null value for both object 'fName' and 'fileUploadId'
0

You are referencing two variables in the fileset

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

namely fileName and fileId. Are these variables defined?

2 Comments

If you look on the network transfer, e.g. via firebug, contains the data send values for fName and fileUploadId? So is the error on the javascript side or on WEB Api side
I have already declared those variable. Problem is only list data is not going from restangular call to api. ( public List<FileuploadResult> fileSet { get; set; } ). I can see the data on console but when i debug on api then it show null.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.