2

I want to send a string via Angular $http to my ASP.NET C# backend. I am using web-forms. However, i get the following error:

POST http://localhost:49730/Default.aspx/get_requested_table 404 (Not Found)

My Angular controller looks like this:

App.controller("MainCtrl", function ($scope, $http) {
   $scope.request_table = function (tableName) {
       $http
           .post("Default.aspx/get_requested_table", tableName)
           .success(function (data) {
               console.log("Success, it worked!");
           });
   };
});

And my HTML looks like this:

<button ng-click="request_table('tblMain')" type='button'>GET IT</button>

And my ASP.NET C# file (aka Default.aspx.cs):

public static string myTable;
[WebMethod]
public static string get_requested_table(string tableName)
{
    var myTable = tableName;
    Console.Write(myTable);
    return myTable;
}

Am I doing something wrong to be getting this error? How can I use Angular's $http methods to speak with my C# backend?

1

1 Answer 1

1

You aren't sending a key/value pair

Try

$http.post("Default.aspx/get_requested_table", {tableName: tableName})
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry I realized I may have been confusing by calling the variable table. It should really be tableName as it is a string. So would I thus have to change the key/value pair to {string:tableName} ?
key is the object key...make it match back end
Awesome! That worked! I set {tableName: tableName}, thanks! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.