如何从控制器动作方法关闭devexpress弹出窗口

时间:2014-02-04 08:02:24

标签: asp.net-mvc-4 devexpress-mvc

我创建了一个包含带有提交按钮的强类型视图的弹出窗口。当用户点击提交按钮时,我将使用post action方法将数据保存到数据库中。现在我想在数据保存时关闭该弹出窗口&显示打开该弹出窗口的父页面。

以下是代码 HomeController的

public class HomeController : Controller
{

    public ActionResult SendProduct(string rowId)
    {
        Product objProduct = new Product();
        return View(objProduct);
    }

    [HttpPost]
    public ActionResult SendProduct(Product objProduct)
    {
        return View(objProduct);
    }
}

产品型号

public class Product
{
    public int ProductId { get; set; }

    [Required]
    public string Name { get; set; }
}

Index.chtm

    @{
    ViewBag.Title = "Home Page";
}
@using DevExpress.Web.Mvc.UI
@using DevExpress.Web.ASPxGridView
@using UI.Infrastructure.Resources;
<script type="text/javascript">
    function OnBeginCallback(s, e) {
        e.customArgs["rowId"] = 123;
    }
    function Click() {
        pcSendProduct.PerformCallback();
        if (!pcSendProduct.IsVisible())
            pcSendProduct.Show();
    }
</script>

<a href="javascript:Click()">Enumalate menu click</a>
<div>
   @Html.DevExpress().Button(settings =>
                                   {
                                       settings.Name = "btnSend";
                                       settings.Width = 80;
                                       settings.Text = "Find";
                                       settings.UseSubmitBehavior = false;
                                       settings.ClientSideEvents.Click = string.Format("function(s, e) {{ Click(); }}");
                                   }).GetHtml()
</div>
  @Html.DevExpress().PopupControl(
    settings =>
    {
        settings.Name = "pcSendProduct";
        settings.Width = 1050;
        settings.Height = 550;
        settings.HeaderText = "Plan Customer Interaction";
        settings.CloseAction = DevExpress.Web.ASPxClasses.CloseAction.CloseButton;
        settings.Styles.Header.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        settings.Styles.Header.VerticalAlign = System.Web.UI.WebControls.VerticalAlign.Middle;
        settings.Styles.Header.Font.Size = 10;
        settings.Modal = true;
        settings.ShowHeader = true;
        settings.ShowCloseButton = true;
        settings.CloseAction = DevExpress.Web.ASPxClasses.CloseAction.CloseButton;
        settings.Left = 1245;
        settings.Top = 300;
        settings.Styles.ModalBackground.BackColor = System.Drawing.Color.Transparent;
        settings.ContentUrl = Url.Action("PlanCustomerInteraction", "PlanCustomerInteraction");
        settings.ShowLoadingPanel = true;
        settings.ClientSideEvents.BeginCallback = "OnBeginCallback";
        settings.ClientSideEvents.EndCallback = "OnPopupEndCallback"; 
    }).GetHtml()

SendProduct.cshtml

    @model Demo.Models.Product

@{
    ViewBag.Title = "SendProduct";
}

<h2>SendProduct</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Product</legend>

        @Html.HiddenFor(model => model.ProductId)

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

因此,在SendProduct POST操作方法中保存数据后,我想关闭发送产品弹出窗口。

请给我解决方法,从控制器动作方法关闭弹出控件。

1 个答案:

答案 0 :(得分:1)

控制器在服务器上运行,而弹出窗口在客户端上,因此您需要添加逻辑以在客户端/ javascript代码中正确关闭弹出窗口。