Click here to Skip to main content
15,041,393 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
I am trying to pass array list of objects to mvc controller by using ngFileUpload because need to send some images with it.

Client side

app.controller('ProprietorController', function ($http, $scope, Upload) {
var existRegDetailVals = [];
$scope.CreateProprietor = function () {
if (Trade.length !== 0) {
    for (var i = 0; i <= Trade.length - 1; i++) {
         existRegDetailVals[i] = {};
         existRegDetailVals[i].RegistrationType = Trade[i].SourceName;
         existRegDetailVals[i].DateOfRegistration = Trade[i].DateRegistration;
         existRegDetailVals[i].RenewalDate = Trade[i].RenewalDate;
     }
     console.log(existRegDetailVals);
}
Upload.upload({
               url: '/Admin/UserManagement/CreateProprietor',
               data: {
                      files: AllProprietorFiles,objExistRegList: existRegDetailVals
                     }
                  }).then(function (response) {
 
                  });
}
})


Server side
C#
[HttpPost]
public ContentResult CreateProprietor(List<ExistingRegistrationDetail> objExistRegList)
{

}

Class File
C#
public partial class ExistingRegistrationDetail
    {
        public int exRegID { get; set; }
        public string RegistrationType { get; set; }
        public Nullable<System.DateTime> DateOfRegistration { get; set; }
        public Nullable<System.DateTime> RenewalDate { get; set; }
    }

Console OutPut

(3) [{…}, {…}, {…}]0: 
{RegistrationType: "Tradelicense", DateOfRegistration: "01/08/2020", RenewalDate: "08/08/2020"}1: 
{RegistrationType: "Tradelicense", DateOfRegistration: "09/08/2020", RenewalDate: "15/08/2020"}2: 
{RegistrationType: "Sec 56 regn", DateOfRegistration: "16/08/2020", RenewalDate: "22/08/2020"}length: 3__proto__: Array(0)


MVC Controller OutPut at debugging

https://i.stack.imgur.com/QrjRc.png

What I have tried:

in first list get 3 parameters correctly as is, but in next lists its leaving one by one values..how to get exactly as is as console output?
Posted
Updated 4-Aug-20 6:06am
v2

1 solution

It looks like your server is using a US locale, and expects dates to be formatted as MM/dd/yyyy, whereas you are passing them as dd/MM/yyyy.

The three dates which work are ambiguous between the two formats, and in US format will be interpreted as 8th January, 8th August, and 8th September respectively.

The three dates which don't work are valid for dd/MM/yyyy, but not for MM/dd/yyyy, so they're getting dropped.

Try passing your dates using an unambiguous format - eg: yyyy/MM/dd. That should work regardless of your server's locale settings.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900