Shubham Khandelwal
Shubham Khandelwal

Reputation: 195

Pass json object as parameter in c# method

I am getting the facebook data of the user using the facebook api as follow:

 function testAPI() {
            FB.api('/me?fields=id,name, birthday, picture.width(100).height(100), email', function (response) {
                if (response && !response.error)
                    //console.log(response);
                    buildProfile(response);
            })
        }

Now I want to pass the response json object to a method in c# as parameter. For doing that I am using the ajax as follows:

function buildProfile(user) {
            $.ajax({
                url: 'callback.aspx/SaveData',
                data: JSON.stringify(user),
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                }
            });
        }

There is method with name SaveData in c#, I have setup a breakpoint on that method.

The url: 'callback.aspx/SaveData' defined above should I have called the callback.aspx page in which SaveData method is present. But somehow I am not able to redirect to the page callback.aspx and to method SaveData in c#.

 public void SaveData(List<string> strings)
 {
            string text = "";
 }

Any help will be greatly appreciated. Thanks in advance.

Upvotes: 2

Views: 4434

Answers (1)

Manoj Kapoor
Manoj Kapoor

Reputation: 69

[WebMethod]
public void SaveData(List<string> strings)
{
      string text = "";
}

The specific method being called needs an attribute WebMethod to be defined to be called using an ajax, I don't see the attribute in your case.

Upvotes: 1

Related Questions