Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

javascript - Angularjs $http.post, asp.net mvc controller gets null

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...