【问题标题】:Rendering a partila view in dialog (pop up)在对话框中渲染局部视图(弹出)
【发布时间】:2014-12-30 11:30:11
【问题描述】:

我尝试使用 jquery 通过单击按钮来显示弹出窗口,该按钮放置在与元素对应的行的每一端。

查看:

<input  type="button" id="DetailButton" value="Details" onclick="GetDetails(this);"/>

脚本:

function GetDetails(sender) {

 var IdElement = $($(sender).parent().parent()).find('input').val();

 $.ajax({
        type: 'GET',
        url: "/ControllerName/ActionName",
        data: encodeURI("IdElement=" + IdElement) ,
        success: function (view) {

              //How to render a view in popup ?

       }

});

}

对话框“DialogDetails”在部分视图中:

<div id="PopUpDetails" >
        <table>
            <thead>
                <tr>
                    <th colspan="1">Element</th>
                </tr>
            </thead>
            <tbody>              
                <%
                    foreach (var Item in Model.List)
                    { %>
                    <tr>                                     
                        <td>
                            <%:Html.DisplayFor(model => Item.IdElement) %>
                        </td>                      
                    </tr>
                <%} %>
            </tbody>
        </table>
    </div>

控制器:

public ActionResult ActionName(int IdElement)
{
       ElementViewModel model = new ElementViewModel ();

       return View("DialogDetails", model);

}

【问题讨论】:

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


    【解决方案1】:

    首先将您的视图作为局部视图返回。 (视图可能很好,但我没有这样使用过)

    那么你要做的就是将ajax调用中的返回结果设置为包含div的对话内容。

    例如

    <div id="dialogDiv"><div>
    

    然后你的 ajax 调用的处理程序这样做:

    $('#dialogDiv').html(view);
    $('#dialogDiv').dialog();
    

    在调用对话框函数之前必须先设置内容。

    这对我有用。

    【讨论】:

    • 有人有其他想法吗?我在 div 中返回部分视图,但不在对话框中
    • 试试这个,在你的局部视图中,为 document.ready 添加一个监听器: $(document).ready(function(){// 然后调用 $('#dialogDiv').dialog() ; 在那里。也许视图没有完成加载。或者在设置视图后调用它之前尝试使用超时。这对我来说绝对有用。
    猜你喜欢
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多