0

this is simple but it dosent work

in angularJS part i have this code :

   var data={"ID":1,"Key":"********"}
            $http.post("/Home/DeleteListItem", data)
                .success(function (data) {
                    alert(JSON.parse(data));
                }).error(function (response) {
                    alert(response);
                });

and C# Part is like this

 [HttpPost]
public JsonResult DeleteListItem(Entity entity)

{

kishAppEntities db = new kishAppEntities();
Stream req = Request.InputStream;
db.Configuration.ProxyCreationEnabled = false;
var data = //some delete query

return new JsonResult()
{
    Data = data,
    JsonRequestBehavior = JsonRequestBehavior.AllowGet

};

}


public  class Entity
{
    int ID { set; get; }
    string Key { set; get; }

}

there is no data in entity i dont have clue aboute it???? enter image description here

i use this post method as second approach but still dosent work

     var entity = { "ID": 1, "Key": "********" }
        $http({
            url: "./general/DeleteListItem",
            method: "POST",
            data: JSON.stringify({
                entity: entity
        }),
        headers: {
            'Content-Type': 'application/json'
        }
        }).success(function(data, status, headers, config) {           
        }).error(function(data, status, headers, config) {
        });
4
  • What is the error you are getting? Based upon the provided code, I can say that angular promise usage is wrong. use $http.post("/Home/DeleteListItem", data).then(function(successResponse){}, function(errorResponse) {}); Commented Dec 16, 2016 at 0:49
  • i dont have a error. problem is i dont get my post data from client Commented Dec 16, 2016 at 0:50
  • please see update Commented Dec 16, 2016 at 0:56
  • Please check my answer below. using .success is not a right way in asynchronous call. refer: codelord.net/2015/05/25/dont-use-$https-success Commented Dec 16, 2016 at 1:02

3 Answers 3

1

Your ID and Key properties are not accessible. Put before your properties public access modifier like this:

public  class Entity
{
    public int ID { set; get; }
    public string Key { set; get; }

}
Sign up to request clarification or add additional context in comments.

Comments

0

try this

$http.post("/Home/DeleteListItem", data)
.then(function(successResponse){
//Your code to handle response

}, 
function(errorResponse) {
//your code to handle error
});

6 Comments

Is that returns any error? Also, check if the call hitting your MVC controller method. Note you won't get the result immediately.
it call mvc contoller and return whit no errore if you see the photo i debug my controller so it call the method it just not have my payload data
sorry.. my network blocks image loading. Please use the [FromBody] attribute on your controller parameter : public JsonResult DeleteListItem([Frombody] Entity entity) {
vs ide dos note recognized [Frombody]
Sorry, there is a typo. it should be [FromBody]
|
0

Try using jquery $.param(data). You can also try angular $httpParamSerializer https://code.angularjs.org/1.4.0/docs/api/ng/service/$httpParamSerializer

Comments

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.