0

我有一个绑定到视图模型的视图。在那个视图上,我有一个链接,它将弹出一个模态 jquery 对话框(使用部分视图)。

我需要的是能够将模型传递给模型弹出窗口,对其进行更新,然后将其传递回视图页面。

我在我的控制器(部分视图)中加载了带有操作方法的模式弹出窗口。但努力将模型传递给它。

有什么建议么?

提前非常感谢。

脚本(在查看页面上):

// ZipLocator modal popup
$(function () {
    $('#ZipLocatorDialog').dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        draggable: false,
        title: 'hi there',
        modal: true,
        show: { effect: 'blind' },
        open: function (event, ui) {
            // Load the ZipLocator action which will return the partial view _ZipLocator
            $(this).load('@Url.Action("ZipLocator", "Shop", New With { .area = "Shop"})');
        },
        buttons: {
            "Close": function () {
                $(this).dialog('close');
            }
        }
    });

    $('#ZipLocatorOpener').click(function () {
        $('#ZipLocatorDialog').dialog('open');
    });
});

部分视图的控制器操作:

<HttpGet()>
    <Compress()>
    Public Function ZipLocator(model As ShopModel) As ActionResult

        Return PartialView("~/Areas/Shop/Views/Shared/Partials/Popups/_ZipLocator.vbhtml", model)

    End Function

正如我所说,jQuery 模态弹出窗口正在工作,我只是很难将我的模型传递给它。

第一步是将模型传递给局部视图(jQuery modal popup)。第二步是在对话框关闭后将更新的模型传回视图。

4

2 回答 2

1

经过一些文档阅读和进一步研究,jQuery UI 对话框有一个数据参数。

// ZipLocator modal popup
$(function () {
    $('#ZipLocatorDialog').dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        draggable: false,
        title: 'hi there',
        modal: true,
        **data: $("#ShopPane").serialize(),**
        show: { effect: 'blind' },
        open: function (event, ui) {
            // Load the ZipLocator action which will return the partial view _ZipLocator
            $(this).load('@Url.Action("ZipLocator", "Shop", New With { .area = "Shop"})');
        },
        buttons: {
            "Close": function () {
                $(this).dialog('close');
            }
        }
    });

    $('#ZipLocatorOpener').click(function () {
        $('#ZipLocatorDialog').dialog('open');
    });
});
于 2012-10-19T15:46:46.053 回答
0

您将需要使用 AJAX POST 将“复杂”模型发送到您的控制器操作 - GET 不起作用(这是.Load 正在使用的)。

或者,只修改ZipLocatoraction 方法的参数以使其接受字符串等“简单”对象,然后在 action 方法中实例化复杂对象会更简单。

我不知道 VB 中的等价物,但在 C# 中,您可以像这样修改您的操作:

[HttpGet]
public ActionResult(string areaName)
{
   var model = new ShopModel { Area = areaName };
    Return PartialView("~/Areas/Shop/Views/Shared/Partials/Popups/_ZipLocator.vbhtml", model);
}
于 2012-06-18T20:44:50.990 回答