0

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.

Edited by lithium112

1
Contributor
1
Reply
9
Views
2 Years
Discussion Span
Last Post by lithium112
0

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.

Edited by lithium112

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.