Member Avatar for lithium112

For my angular controller I have:

app.controller('AdminCtrl', function ($scope, $http) {
    $scope.data = {
        Name: '',
        Password: ''
    },

    $scope.login = function (data) {
        $http({
            method: 'POST',
            url: '/login/postlogin',
            data: JSON.stringify({
                data: $scope.data
            }),
            contentType: "application/json",
            dataType: "json"
        }).success(function (data) {
            alert('success!');
        }).error(function (error) {
            alert(error.message);
        })
    }
});

For my c# controller I have a very basic setup:

        [HttpPost]
        public string PostLogin(string data) {          
            return string.Empty;
        }

My issue is that inside of the c# controller, data is always null. Does anyone know how to pass the name and password params over to the c# controller? I know for a fact that I am recieving values for them from my textboxes that I have. Thanks!

EDIT:
I will recieve the success message/alert.

Member Avatar for lithium112

I finally recieved an answer for this. Basically what needed to be done was to create a couple properties:

public class Data {
            public string Name { get; set; }
            public string Password { get; set; }
        }

And then:

[HttpPost]
        public object PostLogin(Data data) {
            return string.Empty;
        }

After these edits I was able to pass objects from AngularJS to a C# controller. Hopefully this will help somebody one day.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.