简体   繁体   English

如何处理js模板重复的服务器代码?

[英]How to deal with js templates duplication of server code?

I've noticed that I often duplicate razor code by making javascript templates for ajax loading. 我注意到,我经常通过制作用于ajax加载的javascript模板来复制剃刀代码。 And then if I want to change serverside template I have to change js template too, what can I do to minimize such duplication? 然后,如果我想更改服务器端模板,也必须更改js模板,我该怎么做以最大程度地减少此类重复? Thanks for answers, and forgive my english:) 感谢您的回答,请原谅我的英语:)

One of the possible solutions is to use the same template engine on the server side and on the client side for the specific purpose of AJAX requests. 一种可能的解决方案是针对AJAX请求的特定目的,在服务器端和客户端使用相同的模板引擎。

Mustache is a good choice - it's available both for .NET platform and for JavaScript . 小胡子是一个不错的选择-.NET 平台JavaScript都可以使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM