0

我需要能够使用 ajax 调用将淘汰视图模型和一些附加数据发布到 MVC 发布方法。

我的代码如下

   getResultsModel = function () {
        var ogName = $('#resultsname').val();

        var Ids = [];

        for (var i = 1; i < $('#searchResults >tbody >tr').length; i++) {
            var rowNum = i - 1;

            var id = $('#ParticipantId' + rowNum).html();

            Ids.push(id);
        }
        var resultsModel = {
            'orgGroupName': ogName,
            'Ids': Ids
        };

        return resultsModel;
    };

    $("#savequery").click(function () {

        var model = getResultsModel();

        $.ajax({
            url: "/Participant/SaveQuery",
            type: "POST",
            data: {                    
                'model': JSON.stringify(model),
                'viewModel': ko.mapping.toJSON(viewModel)
            },
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                alert('Query Saved Ok');
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Status: " + textStatus + " Error: " + errorThrown);
            }
        });
    });

当我尝试发布时,ajax 调用立即返回错误,正确的语法是什么

4

1 回答 1

0

设法使用以下方法修复它

     $("#savequery").click(function () {

        var model = getResultsModel();

        var resultsModel = {
            'results': model,
            'viewModel':viewModel
        };           

        resultsModel = ko.toJSON(resultsModel);

        $.ajax({
            url: "/Participant/SaveQuery",
            type: "POST",
            data: resultsModel,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                alert('Query Saved Ok');
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Status: " + textStatus + " Error: " + errorThrown);
            }
        });
    });
于 2013-03-06T13:30:20.033 回答