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

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) {
        });
share|improve this question
    
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) {}); – Kalyana Sundaram 1 hour ago
    
i dont have a error. problem is i dont get my post data from client – Pooria.Shariatzadeh 1 hour ago
    
please see update – Pooria.Shariatzadeh 1 hour ago
    
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 – Kalyana Sundaram 1 hour ago
up vote 1 down vote accepted

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; }

}
share|improve this answer
    
thx alot bro you seaved meeee – Pooria.Shariatzadeh 50 mins ago
    
welcome, bro! ;) – a-man 45 mins ago

try this

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

}, 
function(errorResponse) {
//your code to handle error
});
share|improve this answer
    
it dos not work – Pooria.Shariatzadeh 1 hour ago
    
Is that returns any error? Also, check if the call hitting your MVC controller method. Note you won't get the result immediately. – Kalyana Sundaram 1 hour ago
    
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 – Pooria.Shariatzadeh 1 hour ago
    
sorry.. my network blocks image loading. Please use the [FromBody] attribute on your controller parameter : public JsonResult DeleteListItem([Frombody] Entity entity) { – Kalyana Sundaram 1 hour ago
    
vs ide dos note recognized [Frombody] – Pooria.Shariatzadeh 57 mins ago

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

share|improve this answer

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.