看了https://mustache.github.io/你就知道mustache是非常强大的模板引擎,支持多种语言,下面是个简单入门例子:

MVC Model

 public class StudentModel
{
[Key]
public int StuId { get; set; } [Display(Name = "姓名")]
[StringLength()]
[Required(ErrorMessage = "姓名必填")]
public string StuName { get; set; }
[StringLength()]
[Display(Name = "住址")]
[DataType(DataType.MultilineText)]
//[Required(ErrorMessage = "住址必填")]
public string Address { get; set; } [Display(Name = "年龄")]
[Required(ErrorMessage = "年龄必填")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]
public int Age { get; set; }
}

StudentModel

Mvc5WebContext

 public class Mvc5WebContext : DbContext
{
// You can add custom code to this file. Changes will not be overwritten.
//
// If you want Entity Framework to drop and regenerate your database
// automatically whenever you change your model schema, please use data migrations.
// For more information refer to the documentation:
// http://msdn.microsoft.com/en-us/data/jj591621.aspx public Mvc5WebContext() : base("name=Mvc5WebContext")
{
} public System.Data.Entity.DbSet<Mvc5Web.Models.StudentModel> StudentModels { get; set; } }

Mvc5WebContext

Controller

 public class StudentController : Controller
{
public JsonResult JsonList()
{
//StudentModel stu = new StudentModel { StuId = 100, StuName = "wilson100", Age = 100, Address = "HG" };
return Json(db.StudentModels, JsonRequestBehavior.AllowGet);
}
}

html模板

<script id="template" type="text/html">
<table border="">
<tr>
<th>姓名</th>
<th>地址</th>
<th>年龄</th>
</tr>
{{#studentLists}}
<tr>
<td>{{StuName}}
</td>
<td>{{Address}}
</td>
<td>{{Age}}
</td>
</tr>
{{/studentLists}}
</table>
</script>

Ajax请求进行客户端模板输出

  $("#btnTest").click(function () {
$.get("JsonList", function (data) {
var template = $('#template').html();
Mustache.parse(template); // optional, speeds up future uses
var rendered = Mustache.render(template, { studentLists: data });
$('#target').html(rendered);
});
});

mustache.js官方信息

http://mustache.github.io/

https://github.com/janl/mustache.js

使用mustache.js 模板引擎输出html的更多相关文章

  1. vue系列---Mustache.js模板引擎介绍及源码解析(十)

    mustache.js(3.0.0版本) 是一个javascript前端模板引擎.官方文档(https://github.com/janl/mustache.js) 根据官方介绍:Mustache可以 ...

  2. 调研js模板引擎

    js模板引擎越来越多的得到应用,如今已经出现了几十种js模板引擎,国内各大互联网公司也都开发了自己的js模板引擎(淘宝的kissy template,腾讯的artTemplate,百度的baiduTe ...

  3. js模板引擎介绍搜集

    js模板引擎越来越多的得到应用,如今已经出现了几十种js模板引擎,国内各大互联网公司也都开发了自己的js模板引擎(淘宝的kissy template,腾讯的artTemplate,百度的baiduTe ...

  4. js模板引擎--artTemplate

    js模板引擎--artTemplate 以前研究过一段时间的handlebars,但因为其渲染性能略逊于腾讯的artTemplate(在artTemplate的GitHub官网上有推荐的性能测试地址) ...

  5. 浅析js模板引擎

    js模板引擎越来越多的得到应用,如今已经出现了几十种js模板引擎,国内各大互联网公司也都开发了自己的js模板引擎(淘宝的kissy template,腾讯的artTemplate,百度的baiduTe ...

  6. doT js 模板引擎【初探】要优雅不要污

    js中拼接html,总是感觉不够优雅,本着要优雅不要污,决定尝试js模板引擎. JavaScript 模板引擎 JavaScript 模板引擎作为数据与界面分离工作中最重要一环,越来越受开发者关注. ...

  7. 各种JS模板引擎对比数据(高性能JavaScript模板引擎)

    最近做了JS模板引擎测试,拿各个JS模板引擎在不同浏览器上去运行同一程序,下面是模板引擎测试数据:通过测试artTemplate.juicer与doT引擎模板整体性能要有绝对优势: js模板引擎 Ja ...

  8. Filter - Surge.js模板引擎过滤器

    版权所有,转载请注明出处:http://guangboo.org/2014/01/05/filter-surgejs-template-engine 过滤器在surge.js模板引擎中多处用到,其类似 ...

  9. 百度JS模板引擎 baiduTemplate 1.0.6 版

    A.baiduTemplate 简介 0.baiduTemplate希望创造一个用户觉得“简单好用”的JS模板引擎 注:等不及可以直接点左侧导航中的”C.使用举例“,demo即刻试用. 1.应用场景: ...

随机推荐

  1. linux包之procps之vmstat命令

    概述 [root@localhost ~]# rpm -qf /usr/bin/vmstatprocps-3.2.8-25.el6.x86_64 vmstat是一个很全面的性能分析工具,可以观察到系统 ...

  2. You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法

    报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.exampl ...

  3. Hibernate常用配置文件详解

    本文转载自:http://blog.csdn.net/csh624366188/article/details/7578939 初学hibernate的童鞋,刚开应该都有这种感觉,hibernate的 ...

  4. presto访问 Azure blob storage

    当集群使用Azure Blog Storage时,prestoDB无法获取返回结果,在此记录下 如下,hive里面的两个表,一个使用的是本地的hdfs,一个是使用 azure blob storage ...

  5. Hive(二):windows hive ODBC 安装

    针对Windows 32位和64位的系统对应有多个版本的 Hive ODBC Connector, 在安装的过程中,版本必须完全匹配(即:32位的 connector 只能在32位的系统运行,64位的 ...

  6. 剑指offer系列26--正则表达式匹配

    [题目]请实现一个函数用来匹配包括’.’和’*‘的正则表达式.模式中的字符’.’表示任意一个字符,而’‘表示它前面的字符可以出现任意次(包含0次). 在本题中,匹配是指字符串的所有字符匹配整个模式.例 ...

  7. FFTW简介及使用

    http://fftw.org/ FFTW is a C subroutine library for computing the discrete Fourier transform (DFT) i ...

  8. MySQL数据库MyISAM和InnoDB存储引擎的比较

    MySQL有多种存储引擎,MyISAM和InnoDB是其中常用的两种.这里介绍关于这两种引擎的一些基本概念(非深入介绍). MyISAM是MySQL的默认存储引擎,基于传统的ISAM类型,支持全文搜索 ...

  9. bzoj1006 神奇的国度

    Description K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系 ...

  10. [svn]svn merge

    转:http://blog.csdn.net/keda8997110/article/details/21813035 Step by Step 完成merge 目录: Branch的必要性 1.本地 ...