Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

In my Angularjs service I have this code:

$http.post("/EditWorkout/GetId", data).error(function (responseData) {
            console.log("Error !" + responseData);
        });

And I have this method in my ASP.net controller:

       [System.Web.Http.HttpPost]
        public JsonResult GetId(string routineId)
        {
            try
            {
                string x = routineId;
                return Json(new {success = true});
            }
            catch (Exception ex)
            {

                return Json(new { success = false, errorMessage = ex.Message });
            }

        }

I've put a break point on return Json(new {success = true}); and it gets fired, but my routineId is for some reason null, and data which I send using angular's $http.post isn't.

Why is this happening ?

share|improve this question
    
What's inside the data variable? And what's the Content-Type request header being sent? Look at the development console of your Google Chrome browser to see the exact request being made. – Darin Dimitrov Oct 8 '13 at 9:07
    
Yes, it is a variable, I've even tried using "sometext" instead of data, and Content-Type is application/json;charset=utf-8 – hyperN Oct 8 '13 at 9:12
    
And Status Code is HTTP/1.1 200 OK – hyperN Oct 8 '13 at 9:15
up vote 8 down vote accepted

try this:

$http.post("/EditWorkout/GetId", { routineId : data}).error(function (responseData) {
            console.log("Error !" + responseData);
        });
share|improve this answer
    
That solved my problem, tnx :) – hyperN Oct 8 '13 at 10:06
2  
and... why does this work? is it just because routineId is the same name in the controller and json object? – ChiliYago Jan 6 '15 at 22:49
1  
@chiliYago that is correct. Your JSON will be parsed as the C# object that is a parameter(s) on your API controller so they must match or will get an error. – MGot90 Aug 11 '15 at 3:47

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.