Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Can't send Object from AngularJS to Asp.Net 5 service

$
0
0

Hello since in no way I can pass my javascript objects to Asp.Net 5 web api service, I used this method:

 var param = function (obj) {
            var query = '', name, value, fullSubName, subName, subValue, innerObj, i; for (name in obj) {
                value = obj[name]; if (value instanceof Array) {
                    for (i = 0; i < value.length; ++i)
                    { subValue = value[i]; fullSubName = name + '[' + i + ']'; innerObj = {}; innerObj[fullSubName] = subValue; query += param(innerObj) + '&'; }
                } else if (value instanceof Object) {
                    for (subName in value)
                    { subValue = value[subName]; fullSubName = name + '[' + subName + ']'; innerObj = {}; innerObj[fullSubName] = subValue; query += param(innerObj) + '&'; }
                } else if (value !== undefined && value !== null) query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
            } return query.length ? query.substr(0, query.length - 1) : query;
        };

and using it as for example:

updateRoles: function (roleStatusUserModel, successSucceed, successFailed, error) {$http({
                    url: '/api/AdminAccount/UpdateRoles',
                    method: "POST",
                    data: param(roleStatusUserModel),
                    headers: {  'Content-Type': 'application/x-www-form-urlencoded', 'RequestVerificationToken': $rootScope.RequestVerificationToken }
                })
                   .success ...

but this param method does not correctly convert more complex objects and I am not able to receive it at server side. What do I do?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>