1

我有两个模态弹出窗口。弹出窗口 1 显示数据集的详细信息。要编辑数据,我使用链接打开另一个弹出窗口(2)。每当弹出窗口 2 关闭时,我想刷新弹出窗口 1 的内容。

页面(index.aspx)->popup1(partial.ascx)->popup2(partial2.ascx)

除了刷新弹出窗口 1 外,一切正常。

我对 javascript 和 jquery 非常陌生,我不知道如何实现这一点。我已经尝试过 location.reload 和 opener.reload,但它只会重新加载整个页面......

这是我的代码:


弹出窗口 1 的视图:

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

<% using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "CheckOfMeasuresITDialog" }))
   { %>
<%: Html.ValidationSummary(true) %>
<div id="accordion">
    <h3>
        <a href="#" style="margin-left: 20px;">Details</a></h3>
    <div>
        <div>
            <%: Html.ActionLink("Add Measure", "Create", "Measure", new { id = Model.ChangeRequestID, nextView = "./../ChangeRequest2/Partial/_CheckOfMeasuresIT" }, new { @class = "openMeasureDialog", data_dialog_id = "CreateMeasureDialog", data_dialog_title = "Add Measure" })%>
        </div>
        <%: Html.HiddenFor(model => model.ChangeRequestID) %>
        <div class="display-field">
            <table>
                <tr>
                    <th>
                        Submit Date
                    </th>
                </tr>
                <% foreach (var item in Model.measures) %>
                <%{ %>
                <tr>
                    <td>
                        <%: Html.DisplayFor(modelItem => item.submitDate) %>
                    </td>
                 </tr>
                <%} %>
            </table>
        </div>
        <table style="width: 95%; margin-top: 10px;">
            <tr>
                <td>
                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.allMeasuresCompletedIT) %>
                    </div>
                </td>
                <td colspan="3">
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.allMeasuresCompletedIT) %>
                        <%: Html.ValidationMessageFor(model => model.allMeasuresCompletedIT) %>
                    </div>
                </td>
            </tr>
...
        </table>
    </div>
</div>
<fieldset>
    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>
<% } %>`

两个弹出窗口的 Javascript:

$(function () {
    $("#accordion").accordion({ active: 0 });
});
$.ajaxSetup({ cache: false });
$(document).ready(function () {
    $(".openMeasureDialog").live("click", function (e) {
        e.preventDefault();
        $("<div></div>").addClass("MeasureDialog").attr("id", $(this).attr("data-dialog-id")).appendTo("body").dialog({
            title: $(this).attr("data-dialog-title"), close: function () {
                $(this).remove()
            },
            position: ["middle", 20],
            resizable: false,
            modal: true,
            width: 850,
            maxheigth: 800,
            midth: 'auto'
        }).load(this.href);
    });
    $(".close").live("click", function (e) {
        e.preventDefault();
        $(this).closest(".MeasureDialog").dialog("close");
        location.reload(true);
    });
});

弹出窗口 2 的控制器:

[HttpPost]
public ActionResult Create(MeasureViewModel _measure, string nextView)
{
    Measure m = new Measure();
    if (ModelState.IsValid)
    {
        db.Measures.Add(m);
        db.SaveChanges();
        if (Request.IsAjaxRequest())
            return PartialView("Partial/_CloseDialog");
        return RedirectToAction("Index"); 
    }
    ViewBag.ChangeRequestID = new SelectList(db.ChangeRequests, "ChangeRequestID", "initiator", _measure.ChangeRequestID);
    if (Request.IsAjaxRequest())
        return PartialView("Partial/_Create", _measure);
    return View(_measure);
}

部分用于关闭弹出窗口 2:

<script type="text/javascript">
    $(".MeasureDialog").dialog("close");
</script>
4

0 回答 0