5最近是比较烦直接使用Bootstrap里面的模态框,满屏都是模态框代码,看得心烦。然后想起以前使用的BootstrapDialog.show()的方式,挺简单好用的。然后就拿出来分享一下。

1.下载bootstrap-dialog插件

可以在github下载,下载地址:https://github.com/nakupanda/bootstrap3-dialog

也可以在vs的NuGet搜索bootstrap-dialog下载

2.新建一个mvc项目,命名为BootstrapDialog,通过NuGet搜索bootstrap-dialog下载bootstrap3-dialog,将添加如下文件

3.在App_Start文件下的BundleConfig中添加绑定,如下

4.在Hone控制器中添加DialogDemo方法,并添加DialogDemo试图用来展示

5.DialogDemo界面代码如下:

@{
ViewBag.Title = "DialogDemo";
} <h2>DialogDemo</h2>
<button class="btn btn-success" id="alert">BootstrapDialog.alert()</button>
<button class="btn btn-primary" id="show">BootstrapDialog.show()</button>
<button class="btn btn-danger" id="confirm">BootstrapDialog.confirm()</button>
<button class="btn btn-primary" id="load">BootstrapDialog 加载远程页面</button>
@section Scripts {
<script type="text/javascript">
$('#show').click(function () {
BootstrapDialog.show({
title: '提示',
message: '请输入验证码',
closeable: true,
buttons: [{
label: 'Message 1',
action: function (dialog) {
dialog.setMessage('Message 1');
}
}, {
label: '确定',
action: function (dialog) {
dialog.close();
}
}]
});
});
$('#alert').click(function () {
BootstrapDialog.alert({
type: BootstrapDialog.TYPE_WARNING,
title: '提示',
message: "系统错误!",
closeable: true,
buttonLabel: "确定"
});
});
$('#confirm').click(function () {
BootstrapDialog.confirm(
{
title: '删除提示',
message: '是否确定删除?',
type: BootstrapDialog.TYPE_WARNING,
closable: true,
draggable: true,
btnCancelLabel: '取消',
btnOKLabel: '删除', // <-- Default value is 'OK',
btnOKClass: 'btn-warning',
callback: function (result) {
if (result) {
$.ajax({
type: "POST",
url: "/Admin/SMS/Delete",
data: { id: id },
dataType: "json",
success: function (data) {
if (data.result == true) {
//
}
else {
BootstrapDialog.alert({
type: BootstrapDialog.TYPE_WARNING,
title: '提示',
message: data.message,
buttonLabel: "确定"
});
}
}
});
}
}
});
}); $("#load").click(function () {
BootstrapDialog.show({
title: '加载远程页面',
message: function (dialog) {
var $message = $('<div></div>');
var pageToLoad = dialog.getData('pageToLoad');
$message.load(pageToLoad);
return $message;
},
size: BootstrapDialog.SIZE_WIDE,
cssClass: "fade",
closeable: true,
data: {
'pageToLoad': '/Home/Load?msg=' + '我来自遥远的地方...'
}
});
});
</script>
}

6.Home控制器Load方法

public PartialViewResult Load(string msg)
{
return PartialView("LoadPartial", msg);
} view: @model string
<h2>这是远程加载的局部页</h2>
<p>@Model</p>

7.封装BootstrapDialog

function ShowDailog(title,url,success) {
BootstrapDialog.show({
title: title,
type: BootstrapDialog.TYPE_DEFAULT,
size: BootstrapDialog.SIZE_WIDE,
cssClass: "fade",
closeable: true,
message: function (dialog) {
var $message = $('<div></div>');
var pageToLoad = dialog.getData('pageToLoad');
$message.load(pageToLoad);
return $message;
},
data: {
'pageToLoad': url,
},
buttons: [{
label: '<i class="fa fa-close"></i> 取消',
action: function (dialog) {
dialog.close();
}
}, {
label: '<i class="fa fa-check"></i> 确定',
cssClass: 'btn btn-primary',
action: function (dialog) {
success(dialog);
}
}]
});
}

8.调用封装的ShowDailog

function AddMemberSales(t) {
var $this = $(t);
var type = @((int)PositionType.Member);
var parentId =$this.data('key');
var url = '@Url.Action("AddSalesPerson","PersonStruct")?type=' + type + '&parentId=' + parentId;
ShowDailog('添加销售人员', url,
function (dailog) {
var data = $('#team').serialize();
$.ajax({
type: "POST",
url: "@Url.Action("AddSalesPerson", "PersonStruct")",
data: data,
dataType: "json",
success: function (result) {
if (result.Succeeded) {
toastr.success("添数据成功!")
setTimeout(function () {
//self.location.reload(true);
toastr.clear();
}, );
$("#squadMemberTmpl").tmpl(result.ReturnValue).insertBefore($this); }
else {
toastr.error(result.ErrorMessage)
}
},
error: function () {
toastr.error('未知异常导致请求失败,请重试.')
}
});
dailog.close();
});
}

BootstrapDialog模态框的更多相关文章

  1. bootstrap3-dialog:更强大、更灵活的模态框(封装好的模态框)

    用过bootstrap框架的同学们都知道,bootstrap自带的模态框用起来很不灵活,可谓鸡肋的很.但nakupanda开源作者封装了一个更强大.更灵活的模态框——bootstrap3-dialog ...

  2. bootstrap模态框和select2合用时input无法获取焦点(转)

    在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入. 解决方法: 1. 把页面中的  tabindex="-1&qu ...

  3. bootstrap3-dialog:更强大、更灵活的模态框

    用过bootstrap框架的同学们都知道,bootstrap自带的模态框用起来很不灵活,可谓鸡肋的很.但nakupanda开源作者封装了一个更强大.更灵活的模态框——bootstrap3-dialog ...

  4. js控制Bootstrap 模态框(Modal)插件

    js控制Bootstrap 模态框(Modal)插件 http://www.cnblogs.com/zzjeny/p/5564400.html

  5. Bootstrap模态框按钮

    1.触发模态框弹窗的代码 这里复制了一段Bootstrap模态框的代码 <h2>创建模态框(Modal)</h2> <!-- 按钮触发模态框 --> <but ...

  6. boostrap 模态框

    <div class="modal fade" id="myModal" tabindex="-1" role="dialo ...

  7. 解决bootstrap模态框内输入框无法获取焦点

    bootstrap 模态框中的input标签在某些情况下会无法获取焦点. 最终解决方法:去除模态框的 tabindex="-1" 属性即可

  8. 使用RequireJs和Bootstrap模态框实现表单提交

    下面我将使用requirejs结合模态框实现三五行代码部署表单提交操作. 传统开发思路如下:

  9. 使用js实现显示系统当前时间并实现倒计时功能并触发模态框(遮罩)功能

    常常在我们的网页中需要倒计时来触发一些函数,例如遮罩等,在本项目中,通过使用jquery,bootstrap,实现了显示系统当前时间,并且实现了倒计时的功能,倒计时实现后将会弹出模态框(遮罩层).模态 ...

随机推荐

  1. CodeForces-766D Mahmoud and a Dictionary 并查集 维护同类不同类元素集合

    题目链接:https://cn.vjudge.net/problem/CodeForces-766D 题意 写词典,有些词是同义词,有些是反义词,还有没关系的词 首先输入两个词,需要判断是同义还是是反 ...

  2. Windows 10用户可以快速移除U盘

    新浪科技讯,北京时间 4 月 9 日上午消息,据美国科技媒体 The Verge 报道,微软再次证实,从 1809 版本的 Windows 10 开始,插入新闪存盘时“快速移除”(quick remo ...

  3. CentOS7 安装 MySQL 5.7

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz yum -y ...

  4. macOS seria 10.12升级到macOS Mojave的报错:xcrun: error: invalid active developer path, missing xcrun

    今天升级mac系统到macOS mojave后,在终端操作gitlab时遇到一行莫名其妙的错误: xcrun: error: invalid active developer path (/Libra ...

  5. 什么是面向对象以及其意义,prototpye原型

    什么是面向对象: 使用对象时,只关注对象提供的功能,不关注其内部的细节 例如:jquery 什么是对象: 对象是一个整体对外提供一些操作,比如 收音机 面向对象编程OOP的特点: 1.抽象:把主要的特 ...

  6. Linux入门基础(一)

    UNIX/Linux 本身是没有图形界面的,我们通常在 UNIX/Linux 发行版上看到的图形界面实际都只是运行在 Linux 系统之上的一套软件XFree86,现在则是 xorg(X.Org),而 ...

  7. SVN版本号管理工具使用中常见的代码提交冲突问题的解决方法

    相信刚開始学习使用SVN的小伙伴在项目合作开发的过程中一定常常遇到一些影响到自己编写的代码的苦恼.我这里列举了几种常见的问题以及问题的解决方法: 1.误删除和误操作的问题 问题1:有A和B两个人一块合 ...

  8. WebView Js注入

    注入前: 注入后: 主界面: package com.example.webviewjsdemo; import android.os.Bundle; import android.app.Activ ...

  9. redis作为缓存场景使用,内存耗尽时,突然出现大量的逐出,在这个逐出的过程中阻塞正常的读写请求,导致 redis 短时间不可用

    redis 突然大量逐出导致读写请求block   内容目录: 现象 背景 原因 解决方案 ref 现象 redis作为缓存场景使用,内存耗尽时,突然出现大量的逐出,在这个逐出的过程中阻塞正常的读写请 ...

  10. Spring 注解拦截器使用详解

    Spring mvc拦截器 平时用到的拦截器通常都是xml的配置方式.今天就特地研究了一下注解方式的拦截器. 配置Spring环境这里就不做详细介绍.本文主要介绍在Spring下,基于注解方式的拦截器 ...