在jQuery ui对话框窗口中加载MVC 4 Partial View

时间:2013-04-04 19:56:07

标签: jquery asp.net-mvc jquery-ui asp.net-mvc-4

我正在尝试在jQuery ui对话框窗口中显示部分视图,但我对加载功能没有太多运气。对话框窗口打开但我看不到局部视图的内容。

JS代码位于外部js文件中。警报显示。

$(document).ready(function () {
    $('#dialog-modal').dialog({
        autoOpen: false,
        //width: 200,
        height: 400,
        modal: true,
        open: function (event, ui) {
            //alert("test");
            $(this).load("@Url.Action(\"OpenDialogWindow\", \"Home\" )");
        }
    });
});

=============================================== ===================

我的div在这样的母版页上。

 <div id="dialog-modal" title="Select a city to see the listings">  </div> 

========================

我的ActionResult看起来像这样。我确实将视图设置为局部视图。

public ActionResult OpenDialogWindow()
        {
            return PartialView("DialogView");
        }

========================

我的观点看起来像这样。

@using TheSGroup_Web.ViewModels
@model CitiesViewModel

    <p>this is the content.
    </p>

2 个答案:

答案 0 :(得分:10)

我不确定MVC 2或3,但在MVC 4中,这就是我开始工作的方式。

$(document).ready(function () {
    $('#dialog-modal').dialog({
        autoOpen: false,
        modal: true,
        open: function (event, ui) {
            //alert("test");
            $(this).load("/Controller/Action");
        }
    });
});

function OpenDialog() {
    $('#dialog-modal').dialog('open');
}

答案 1 :(得分:0)

您可以随时向部分视图发出ajax请求,检查状态代码,使某些东西变得疯狂,并且您需要执行其他操作,并将响应数据存储在变量中。如果状态代码是200(OK),那么使用open:方法中的变量加载对话框,否则,做一些很酷的事情...我不知道我头顶的确切代码,但它不会'我不认为是凝灰岩......

相关问题