Question

I have a JQuery Dialog that is used to pass some information to the server. The ActionResult Method then generates a document. This is then returned to the browser. All good so far.

However, I am wanting to close the dialog when the document is returned.

Was it helpful?

Solution

if u using ajax call u can use success function

$.ajax({
    type: "POST",
    url: 'url',      
    success: function (data) {
        close dialog here.
    }
})

if u using mvc ajax from u can use success function of this helper

@Ajax.BeginForm("", new AjaxOptions { OnSuccess="close_dialog()"})

and if u submit the form without ajax u can send some messegge to view and close the dialog or just dont open it:)

 [HttpPost]       
    public ActionResult YourAction(UrModel model)
    {
        if (ModelState.IsValid)
        {
            //Use any stuff to send the message to View 
            ViewBag.close_dialog = true;
            ViewData["close_dialog"] = true;
            //or temp data or modelstate or somethins else.
        }
        return View(model);
    }

and in view

<script type ="text/javascript">
@if (ViewBag.close_dialog)
{
    <text>
//javscript here
close_dialog();
    </text>
}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top