开发者

AjaxContent javascript argument does not contain function get_data()

I have created an ActionLink in an MVC application that successfully calls a server side method and returns Json.

My problem is that in the OnSuccess javascript function the AjaxContext argument recieved does not contain the .get_data() function. Nor any of the other functions specified in this SO article.

The context object only returns the data that was constructed in the server side method.

@Ajax.ActionLink("Remove from cart", "RemoveFromCart/" + @item.Id, new AjaxOptions() { OnSuccess = "handleUpdate", HttpMethod="POST" })


[HttpPost]
        public ActionResult RemoveFromCart(int id)
        {
            ShoppingBasket basket = ShoppingBasket.GetShoppingBasket(this.HttpContext);
            basket.Items.Remove(basket.Items.Find(i => i.Id == id));
            ShoppingCartRemoveViewModel results = new ShoppingCartRemoveViewModel
            {
                DeleteId = id,
                Message = id + " has been removed."
            };

            return Json(results);
        }


<script type="text/javascript">
    function handleUpdate(context) {
        alert('deleted ' + context.DeleteId);
        context.get_data(); <-- ERROR
    }
</script>

The Context does not appear to be an AjaxContext object, despite calling Json() on the return data. 开发者_JAVA技巧Any Ideas?

Thanks


Firebug shows the context object is an XmlHttpRequest object

After fiddling around for a bit, I finally got the json data using

<script type="text/javascript">
   function handleUpdate(context) {
     alert(context.responseText);
   }
</script>


I had better luck with:

(context.valueOf() == "blah has been removed")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜