在调用ajax后使用ViewModel返回视图

时间:2016-11-08 11:13:28

标签: c# jquery ajax asp.net-mvc

我从ajax函数调用一个动作,在其中获取我的ViewModel,然后尝试用其他ViewModel打开新视图,但redirectToAction和返回视图都没有工作。我看到的其他答案只需打开其他视图而不发送ViewModel

ajax call

$("#delete").click(function () {
                var model = $("#forma").serialize();

                console.log("delete", model);

                $.ajax({
                    url: '@Url.Action("DeleteDevices", "package")',
                    contentType: 'application/json; charset=utf-8',
                    dataType: "json",
                    data: model,
                    success: function (result) {
                    }
                });

                return false;
            });

和contorller什么都不做

 public ActionResult DeleteDevices(PackageDevicesViewModel viewModel)
        {
//model processing here
        return View(NewModel);
}

1 个答案:

答案 0 :(得分:0)

变化

data: model,

要     data:JSON.parse(JSON.stringify($(“form”)。serializeArray()))