MVC-弹出窗口 [英] MVC-pop up windows

查看:263
本文介绍了MVC-弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建立在MVC的弹出窗口(在浏览器不是新选项卡)。有谁知道如何做到这一点?

I need to create pop up windows in mvc(not new tab in browser). Does anyone know how to do this?

推荐答案

一种可能性是使用 jQuery UI的对话框

修改

这个想法是有一个返回局部视图一个ajax的行动。该行动(HTML)的结果放置在弹出的容器内,并在Ajax调用打开弹出窗口的成功处理程序。下面是一些示例code:

The idea would be to have an ajax action that returns a partial view. The result of that action (html) is placed inside the container of the popup and on the success handler of the ajax call you open the popup. Here is some sample code:

@Ajax.ActionLink("Open popup", "SomeAction", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess="openPopup" })<br />

<div id="result" style="display:none;"></div>

<script type="text/javascript">
$(document).ready(function() {
    $("#result").dialog({
        autoOpen: false,
        title: 'Title',
        width: 500,
        height: 'auto',
        modal: true
    });
});
function openPopup() {
    $("#result").dialog("open");
}
</script>

然后,你必须在返回的局部视图控制器添加操作

Then you have to add the action in the controller that returns the partial view

 [HttpGet]
 public PartialViewResult SomeAction()
 {
      return PartialView();
 }

地方无论你在局部视图需要,您还可以包括动作等参数。

Place whatever you need in the partial view, you may also include parameters in the action, etc.

祝你好运!

这篇关于MVC-弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆