使用JQuery post方法处理MVC操作结果

时间:2012-07-11 08:49:34

标签: asp.net-mvc-3

我正在调用MVC动作,如下所示:

var RestaurantDetailsUIforForeignWidget = {
    frmId: '',
    onFormSubmit: function () {
        var frm = $(RestaurantDetailsUIforForeignWidget.frmId);
        var divResult;
        $('.offerbox').hide();
        $.post(frm.attr('action'), frm.serialize(), function (html) {
            // $('#section-time-slots').html(html)
            $('#contentAll').html(html);
            DisplayOffer();
        });
        return false;
    },
    updateTimeDesc: function () {
        $('#time').val($('#SittingTime option:selected').html());
    },
    init: function (frmId) {
        RestaurantDetailsUIforForeignWidget.frmId = frmId;
        $('#SittingTime').bind('change', RestaurantDetailsUIforForeignWidget.updateTimeDesc);
        $(frmId).bind('submit', RestaurantDetailsUIforForeignWidget.onFormSubmit);
        RestaurantDetailsUIforForeignWidget.updateTimeDesc();
    }
};

正如您所看到的,$('#contentAll').html(html);使用结果更新整个视图内容。我想要的是从html输出中获取一个div并改为更新$('#section-time-slots')

请帮帮我们......谢谢:)

1 个答案:

答案 0 :(得分:1)

试试这个:

    $.post(frm.attr('action'), frm.serialize(), function (html) {
        $('#section-time-slots').html($("#IdOfRequiredElementInResponse", html).html());
        DisplayOffer();
    });