最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML templating solution for both ASP.NET MVC and browser? - Stack Overflow

programmeradmin2浏览0评论

I'm trying to find an HTML templating solution that will work both on my ASP.NET MVC application (.NET 4, IIS 7.5) and in the browser. The reason is to the the same code to render HTML both on the server (performance, outputting to mobile, etc) or on the browser (refreshing data via AJAX). This is not a new problem, but I am wondering if current technology trends have changed the answer.

A couple of ideas I am considering:

  • Use mustache templates with are available in both JavaScript and .NET.
  • Use a port of the Razor View Engine to JavaScript like considered in Javascript + Razor == Jazor?.
  • Take a position like Micro Templates Are Dead... forget about it and just use JavaScript (IronJS?) and the DOM (jsdom)

ASP.NET MVC View Engine Comparison looked relavent, but there is no mention of mustache.

Update: The client-side templating throwdown: mustache, handlebars, dust.js, and more from LinkedIn Engineering rates mustache in it's top four, with it being the only one with native .NET rendering (vs requiring server-side JavaScript to render on the server).

I'm trying to find an HTML templating solution that will work both on my ASP.NET MVC application (.NET 4, IIS 7.5) and in the browser. The reason is to the the same code to render HTML both on the server (performance, outputting to mobile, etc) or on the browser (refreshing data via AJAX). This is not a new problem, but I am wondering if current technology trends have changed the answer.

A couple of ideas I am considering:

  • Use mustache templates with are available in both JavaScript and .NET.
  • Use a port of the Razor View Engine to JavaScript like considered in Javascript + Razor == Jazor?.
  • Take a position like Micro Templates Are Dead... forget about it and just use JavaScript (IronJS?) and the DOM (jsdom)

ASP.NET MVC View Engine Comparison looked relavent, but there is no mention of mustache.

Update: The client-side templating throwdown: mustache, handlebars, dust.js, and more from LinkedIn Engineering rates mustache in it's top four, with it being the only one with native .NET rendering (vs requiring server-side JavaScript to render on the server).

Share Improve this question edited May 23, 2017 at 12:30 CommunityBot 11 silver badge asked Jul 22, 2011 at 19:54 Kevin HakansonKevin Hakanson 42.3k23 gold badges129 silver badges158 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

I would highly remend mustache for your application. You have already mentioned abt the fact that it has a server side rendering engine and also a strong munity backing. Apart from this the major reason why I would remend mustache is for Performance of the templating engine. I have played around with the same and none of the other JS templating solution could match the performance of mustache.

What I would like more is documentation around the library but you should be able to work around this.

I have done that using Spark view engine, it is quite good with the template where you can use it from and js.

发布评论

评论列表(0)

  1. 暂无评论