Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question
    
Do you have a ScriptManager on your page? (msdn.microsoft.com/en-us/library/…) – Steve Danner 15 hours ago
up vote 0 down vote accepted

You aren't sending a key/value pair

Try

$http.post("Default.aspx/get_requested_table", {tableName: tableName})
share|improve this answer
    
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} ? – Kangze Huang 15 hours ago
    
key is the object key...make it match back end – charlietfl 15 hours ago
    
Awesome! That worked! I set {tableName: tableName}, thanks! :) – Kangze Huang 15 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.