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,返回一个分部视图 直接可以渲染,不 ...
随机推荐
- 你真的了解mysql的varchar字段的长度有多少吗?
今天在设计系统字段的时候, 发现自己对varchar还不够了解.我设了一个字段.类型为VARCHER,然后我就往里面测试性了写了东西.发现没有多少就满了.我觉得奇怪,5.5版本以上的MYSQL不是有6 ...
- IE8,IE9,IE10,FireFox 的CSS HACK
#employeesView { top: 732px; //所有浏览器 top: 730px\9;//所有IE浏览器 } @media all and (min-width:0) { #employ ...
- 线段树 [成段更新] HDU 1698 Just a Hook
成段更新,需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候. 此处建议在纸上模拟一遍. Problem Descript ...
- xcode target
A target specifies a product to build and contains the instructions for building the product from a ...
- MyReport演示下载连接和相关文章索引
演示地址 Flex集成方式 (旧版2.6) HTML集成方式 MyReport产品站点 NEW 相关文章 ------------------------2.6下面版本号--------------- ...
- hdu 4454 Stealing a Cake(三分法)
给定一个起始点,一个矩形,一个圆,三者互不相交.求从起始点->圆->矩形的最短距离. 自己画一画就知道距离和会是凹函数,不过不是一个凹函数.按与水平向量夹角为圆心角求圆上某点坐标,[0, ...
- MYSQL中取当前年份的第一天和当前周,月,季度的第一天/最后一天
mysql 获取当年第一天的年月日格式:SELECT DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY); MySQL里获取当前week.month ...
- android 自己定义开关(SwitchButton)
近期心血来潮,写了一个自己定义仿iPhone的开关. 有须要的同学能够来下载啦.支持点击自己主动滚动,速率能够自己依据须要改动.触摸滚动,大小自己定义,支持改动样式.就不录制动画,就上传了两张图给大家 ...
- 2010多校第一题 hdu3440House Man 差分约束系统
给我们n座房子,房子的高度各不相同, 从最低的房子开始, 每次跳到更高的房子, 跳n-1次最能跳到最高的房子了,但是每次跳跃的距离不能超过d 将这些房子在一维的方向上重新摆放(但是保持输入时的相对位置 ...
- oracle spfile和pfile文件(转)
--======================== -->Oracle 参数文件 --======================== /* 参数文件(10g中的参数文件) 主要用来记录数据库 ...