gpt4 book ai didi

c# - MVC3 Razor 和模态弹出窗口

转载 作者:太空狗 更新时间:2023-10-30 00:08:41 24 4
gpt4 key购买 nike

我需要获得一个模态弹出窗口,显示一个将数据保存回数据库的表单。有这样做的好例子吗? Ajax 更灵活还是使用 jquery 对话框?

最佳答案

我用过 JQuery UI Dialog plugin并使用 JQuery 通过 ajax 加载模态对话框,我对此非常满意。

我不得不修改我的代码来给你一些有用的东西,所以对于任何语法错误我深表歉意,但我使用这个 jquery,

$('#MyAtag').click(function () {
// Add a container for the modal dialog, or get the existing one
var dialog = ($('#ModalDialog').length > 0) ? $('#ModalDialog') : $('<div id="ModalDialog" style="display:hidden"></div>').appendTo('body');
// load the data via ajax
$.get( 'mycontroller/myaction', {},
function (responseText, textStatus, XMLHttpRequest) {
dialog.html(responseText);
dialog.dialog({
bgiframe: true,
modal: true,
width: 940,
title: 'My Title'
});
}
);
});

它将对 ajax“get”的调用绑定(bind)到链接的“click”事件。 ajax get 请求从我的 MVC 项目中的相应操作返回部分 View ,然后显示在模态对话框中。

下面是 Controller 的粗略示例

    public ActionResult MyAction()
{
// Do Some stuff
//...

// If the request is an ajax one, return the partial view
if (Request.IsAjaxRequest())
return PartialView("PartialViewName");

// Else return the normal view
return View();
}

对话框的 View 只是一个普通的局部 View 。

我使用以下 .css,它使模式对话框后面的页面“变灰”

.ui-widget-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #AAA url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;
opacity: .8;
filter: Alpha(Opacity=30);
}

您可能需要修改 #ModalDialog 的 css 以使其看起来正确,

关于c# - MVC3 Razor 和模态弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6566298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com