通过ActionResult返回Document后关闭Jquery对话框

时间:2013-06-08 16:19:54

标签: jquery asp.net-mvc document actionresult

我有一个JQuery Dialog,用于将一些信息传递给服务器。然后ActionResult方法生成一个文档。然后将其返回到浏览器。到目前为止一切都很好。

但是,我希望在返回文档时关闭对话框。

1 个答案:

答案 0 :(得分:-1)

如果你使用ajax调用你可以使用成功函数

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

如果您使用来自u的mvc ajax可以使用此帮助程序的成功函数

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

如果您在没有ajax的情况下提交表单,您可以发送一些messegge来查看和关闭对话框,或者只是不打开它:)

 [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);
    }

并在视野中

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

相关问题