MVC 2 - 显示包含的局部视图一个jQuery对话框 [英] MVC 2 - Display a jquery dialog that contains a partial view

查看:89
本文介绍了MVC 2 - 显示包含的局部视图一个jQuery对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我想显示一个对话框,并且对话框的内容是从局部来看,_TestPartial。

下面是部分观点:

 <%@控制语言=C#继承=System.Web.Mvc.ViewUserControl%GT;< D​​IV ID =测试称号=基本对话>
    < P>这只是测试< / P>
< / DIV>

现在,如果我把我的.aspx的测试 DIV所显示的对话框中,将显示就好了。或者,如果我从我的页面调用部分正确的,它会显示这仅仅是一个测试就好了。我只是不知道如何让一个jQuery对话框中显示的部分。我已经尝试了一些东西,比如有我的电话对话的行动, TestAction ,这使得 _TestPartial ,但是,这并不甚至工作。我有一种感觉,我很想念code的关键部分地方寿。这里是我的对话框code(其所谓自动根据选择列表中选择):

 如果($('#SelectListID选项:选择。)文本()=='测试'){
                    $('#测试)。对话框({                        宽度:400,
                        可调整大小:假的,
                        标题:测试对话框,
                        打开:函数(事件,UI){
                            $(本).load(@ Url.Action('TestAction'));
                        },
                        纽扣: {
                            关闭:功能(){
                                $(本).dialog(亲密);
                            }
                        }
                    });
                }


解决方案

我记得以前有类似的问题。我们增加了一个对话框容器中,然后装在内部DIV的局部视图。

 < D​​IV ID =dialogcontainer>
    < D​​IV ID =dialogcontent>< / DIV>
< / DIV>$(#dialogcontainer)。对话框({
    宽度:400,
    可调整大小:假的,
    标题:测试对话框,
    打开:函数(事件,UI){
        $(#dialogcontent)负载(@ Url.Action('TestAction'));
    },
    纽扣: {
        关闭:功能(){
            $(本).dialog(亲密);
        }
    }
});

Okay, so I'm trying to display a dialog, and the contents of that dialog is from a partial view, _TestPartial.

Here is the partial view:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<div id="test" title="Basic dialog">
    <p>This is just a test</p>
</div>

Now, if I put the test div in my .aspx that is displaying the dialog, it will show just fine. Or if I call the partial right from my page it will show 'This is just a test' just fine. I just have no idea how to make a jquery dialog display a partial. I've tried a few things, such as having my dialog call an Action, TestAction, which renders the _TestPartial, but that doesnt even work. I have a feeling I'm missing a key piece of code somewhere tho. Here is my dialog code(its called automatically based on a select list choice):

if ($('#SelectListID option:selected').text() == 'Test') {
                    $('#test').dialog({

                        width: 400,
                        resizable: false,
                        title: 'Test dialog',
                        open: function(event, ui) {
                            $(this).load("@Url.Action('TestAction')");
                        },
                        buttons: {
                            "Close": function (){
                                $(this).dialog("close");
                            }
                        }                        
                    });
                }

解决方案

I remember having a similar problem before. We added a dialog container and then loaded the partial view in an inner div.

<div id="dialogcontainer">
    <div id="dialogcontent"></div>
</div>

$("#dialogcontainer").dialog({
    width: 400,
    resizable: false,
    title: 'Test dialog',
    open: function(event, ui) {
        $("#dialogcontent").load("@Url.Action('TestAction')");
    },
    buttons: {
        "Close": function (){
            $(this).dialog("close");
        }
    }                        
});

这篇关于MVC 2 - 显示包含的局部视图一个jQuery对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆