Pergunta

I have created popup which contain a strongly typed view with submit button. When user click on submit button I am going to save data into database in post action method. Now I want to close that popup when data get saved & display parent page from which that popup was opened.

Following is the code 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);
    }
}

Product model

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")
}

So after saving data in SendProduct POST action method I want to close Send product popup.

Please give me solution to close popup controll from controller action method.​

Foi útil?

Solução

The controller runs on the server, while your popup is on the client, so you need to add the logic to close the popup at the right time in the client/javascript code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top