开发者

Is it possible to prevent invocation of jQuery load callback function when returning from action method in ASP.NET MVC?

Given the following jQuery (loading a partial view when clicking an arrow button and invoking a callback function that increments a variable):

    var current_number = 1;
    $("#right_开发者_高级运维arrow").click(function () {
        $("#some_partial_view").empty().load(ActionUrls.rightArrowClick, { pageNo: current_number + 1 }, function () {
            current_number++;
        })
    });

and the answering action method in an MVC controller:

    public ActionResult rightArrowClick(int number)
    {
        return PartialView("_partialView", getModel(number));
    }

Is it possible to prevent the load function's callback to be invoked, or, pass a parameter to it to prevent the current_number to incremented? I realize it's probably not a good idea to store state on the client side, but haven't found another way to do it in this particular case (#n00b).


Could you search the responseText sent back by jQuery to your callback -

    var current_number = 1;
    $("#right_arrow").click(function () {
        $("#some_partial_view").empty().load(ActionUrls.rightArrowClick, { pageNo: current_number + 1 }, function (response, status, xhr) {
            if(response.indexOf('mySearchString') > -1) {
             current_number++;
            }

        })
    });

Obviously this will only work if there's something in your responseText that indicates the counter shouldn't be incremented.


Try returning a HTTP error code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜