MVC 5 Ajax + bootstrap+ handle bar 例: 实现service 状态
<script src="../../Scripts/handlebars-v1.3.0.js"></script>
<script id="service-status-details-template" type="text/x-handlebars-template">
{{#each values}}
<div class="top-buffer-10">
<div class="pull-left">{{ServiceName}}</div>
<span style="margin-left: 15px;"> </span>
<div class="pull-right">
<span class="service-details-time">{{TimeDurationAgo}} AGO</span>
{{#if IsUp}}
<span class="glyphicon glyphicon-ok-sign" style="color: #5cb85c;"></span>
{{else}}
<span class="glyphicon glyphicon-exclamation-sign" style="color: #ff4f28;"></span>
{{/if}}
</div>
</div>
{{/each}}
</script>
<div style="z-index: 10;display: none;" id="service-status-details">
</div>
<a id="service-status" style="margin-left: 30%;" data-placement="bottom" href="#"></a>
<script>
var serviceStatusUrl = '@Url.Action("GetMonitoringServicesStatus")';
$(document).ready(function () {
$("#service-status").popover(
{
html: true,
content: function () {
return $('#service-status-details').html();
}
});
refreshServiceStatus();
//window.setInterval(refreshServiceStatus, 5 * 60 * 1000 /*frequency set to 5 mins*/);
});
function refreshServiceStatus() { /*should be change to set interval*/
$.ajax({
type: 'POST',
url: serviceStatusUrl, /*this value is set in _monitoringServices.cshtml */
success: function (data) {
applyToJsTemplate("service-status-details", "service-status-details-template", data);
if (!data.isOk) {
$("#service-status").attr("class", "btn glyphicon glyphicon-exclamation-sign");
$("#service-status").css("color", "#ff4f28");
} else {
$("#service-status").attr("class", "btn glyphicon glyphicon-ok-sign");
$("#service-status").css("color", "#5cb85c");
}
},
dataType: "json"
});
}
function applyToJsTemplate(layoutId, templateId, data) {
$("#" + layoutId).html(Handlebars.compile($("#" + templateId).html())(data));
}
</script>
Css
<style>
.popover-content {
background-color: #dadada;
}
.service-details-time {
color: #adadad;
} .service-details-name {
color: #5d5d5d;
}
.popover {
max-width: 100%;
} </style>
C#
public JsonResult GetMonitoringServicesStatus()
{
if (DateTime.Now.Second % 2 == 0)
{
var serviceList = Builder<MonitoringServicesModel>.CreateListOfSize(5)
.TheFirst(1).With(m => m.ServiceName, "Active Directory").With(m => m.IsUp, false).With(m => m.TimeDurationAgo, "11 MINS")
.TheNext(1).With(m => m.ServiceName, "aZure.Microsoft.com").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "5 MINS")
.TheNext(1).With(m => m.ServiceName, "aZure Preview Portal").With(m => m.IsUp, false).With(m => m.TimeDurationAgo, "16 MINS")
.TheNext(1).With(m => m.ServiceName, "Management Portal").With(m => m.IsUp, false).With(m => m.TimeDurationAgo, "31 MINS")
.TheNext(1).With(m => m.ServiceName, "Network Infrastructure").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "1 MINS")
.Build();
var allUp = serviceList.All(s => s.IsUp);
return Json(new { isOk = allUp, values = serviceList }, JsonRequestBehavior.AllowGet);
}
else
{
var serviceList = Builder<MonitoringServicesModel>.CreateListOfSize(5)
.TheFirst(1).With(m => m.ServiceName, "Active Directory").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "1 MINS")
.TheNext(1).With(m => m.ServiceName, "aZure.Microsoft.com").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "26 MINS")
.TheNext(1).With(m => m.ServiceName, "aZure Preview Portal").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "16 MINS")
.TheNext(1).With(m => m.ServiceName, "Management Portal").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "5 SECONDS")
.TheNext(1).With(m => m.ServiceName, "Network Infrastructure").With(m => m.IsUp, true).With(m => m.TimeDurationAgo, "1 MINS")
.Build();
var allUp = serviceList.All(s => s.IsUp); return Json(new { isOk = allUp, values = serviceList }, JsonRequestBehavior.AllowGet);
}
} public class MonitoringServicesModel
{
public string ServiceName { get; set; } public string TimeDurationAgo { get; set; } public bool IsUp { get; set; }
}
MVC 5 Ajax + bootstrap+ handle bar 例: 实现service 状态的更多相关文章
- 用最基本的EF+MVC+JQ+AJAX+bootstrap实现权限管理的简单实例 之登陆和操作权限
先来一堆关于上篇文章的废话(不喜者点此隐藏) 今天把博客加了个小功能,就是点标题可以隐藏或展示相关内容,做法很傻,就是引用了bootstrap的两个css类和全部的js文件,其实这样的小功能完全应该自 ...
- MVC遇上bootstrap后的ajax表单模型验证
MVC遇上bootstrap后的ajax表单验证 使用bootstrap后他由他自带的样式has-error,想要使用它就会比较麻烦,往常使用jqueyr.validate的话只有使用他自己的样式了, ...
- 转:MVC遇上bootstrap后的ajax表单验证
使用bootstrap后他由他自带的样式has-error,想要使用它就会比较麻烦,往常使用jqueyr.validate的话只有使用他自己的样式了,而且有模型在使用模型验证更方便点.怎么解决呢? 当 ...
- Asp.Net MVC Unobtrusive Ajax
1. Unobtrusive JavaScript介绍 说到Unobtrusive Ajax,就要谈谈UnobtrusiveJavaScript了,所谓Unobtrusive JavaScript ...
- Spring Ajax一个简单样例
配置不说了.要在前面helloworld的样例基础上弄. 相同在hello下新建ajax.jsp <%@ page language="java" contentType=& ...
- ASP.NET MVC 学习笔记-7.自定义配置信息 ASP.NET MVC 学习笔记-6.异步控制器 ASP.NET MVC 学习笔记-5.Controller与View的数据传递 ASP.NET MVC 学习笔记-4.ASP.NET MVC中Ajax的应用 ASP.NET MVC 学习笔记-3.面向对象设计原则
ASP.NET MVC 学习笔记-7.自定义配置信息 ASP.NET程序中的web.config文件中,在appSettings这个配置节中能够保存一些配置,比如, 1 <appSettin ...
- MVC使用ajax异步刷新时怎样输出从后台中传过来的JSON数据
前言 这几天在学习MVC使用AJAX异步刷,因为是新手.所以在js中传参数到后台以及后台返回数据到前台怎么接受,怎么前台遍历出JSON数据都开始不知道,相信新手在使用时跟我一样会遇到,这里我就和大家分 ...
- ASP.NET MVC 实现AJAX跨域请求方法《1》
ASP.NET MVC 实现AJAX跨域请求的两种方法 通常发送AJAX请求都是在本域内完成的,也就是向本域内的某个URL发送请求,完成部分页面的刷新.但有的时候需要向其它域发送AJAX请求,完成数据 ...
- asp.net mvc 使用ajax请求 控制器 (PartialViewResult)分部的action,得到一个分部视图(PartialView)的HTML,进行渲染
在asp.net mvc 使用ajax请求获取数据的时候,我们一般是返回json或者xml,然后解析这些数据进行渲染,这样会比较麻烦,可以请求一个 分部action,返回一个分部视图 直接可以渲染,不 ...
随机推荐
- Wix打包系列(二)用户界面和本地化操作
原文:Wix打包系列(二)用户界面和本地化操作 上一章节,我们已经大概知道如何对文件进行打包安装,不过我们也注意到,通过对Sample.wxs的编译链接,生成的msi安装包没有任何用户界面,只有一个安 ...
- 启动、停止、重启 MySQL 常见的操作方法:
启动.停止.重启 MySQL 常见的操作方法: 简单罗列 一.启动方式 1.使用 service 启动:service mysqld start 2.使用 mysqld 脚本启动:/etc/inint ...
- Maven中Spring-Data-Redis存储对象(redisTemplate) (转)
Redis是一种nosql数据库,在开发中常用做缓存.Jedis是Redis在java中的redis- client.在此之前,希望已经了解redis的基本使用和Maven的使用.建立Maven Pr ...
- Python – Get Object’s Class Name | Ridge Solutions, Ireland
Python – Get Object’s Class Name | Ridge Solutions, Ireland Python – Get Object’s Class Name Author: ...
- 【架构之路之WCF全析(一)】--服务协定及消息模式
上周微软开公布会说.NET支持全然跨平台和并开放Core源代码的新闻,让我们顿时感到.NET要迎来它的春天.尽管早在几年前.NET就能开发Android和IOS,可是这次的跨平台把Linux都放到了微 ...
- POJ 2536 Gopher II(二分图的最大匹配)
题目链接:http://poj.org/problem?id=2536 题意:已知有n仅仅老鼠的坐标,m个洞的坐标,老鼠的移动速度为V,S秒以后有一仅仅老鹰要吃老鼠,问有多少个老鼠被吃. 非常明晰,二 ...
- 《Javascript高级程序设计》读书笔记之对象创建
<javascript高级程序设计>读过有两遍了,有些重要内容总是会忘记,写一下读书笔记备忘 创建对象 工厂模式 工厂模式优点:有了封装的概念,解决了创建多个相似对象的问题 缺点:没有解决 ...
- Android编程获取网络连接状态及调用网络配置界面
获取网络连接状态 随着3G和Wifi的推广,越来越多的Android应用程序需要调用网络资源,检测网络连接状态也就成为网络应用程序所必备的功能. Android平台提供了ConnectivityMan ...
- 全面认识Eclipse中JVM内存设置(转)
这里向大家描述一下Eclipse中如何进行JVM内存设置,JVM主要管理两种类型的内存:堆和非堆.简单来说堆就是Java代码可及的内存,是留给开发人员使用的:非堆就是JVM留给自己用的,所以方法区.J ...
- java 配置及安装Eclipse
jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for ...