这是我用我的车把模板
模板示例:位于〜/模板/ template123.html
<script id="template123" type="text/html">
<div>someTemplate</div>
</script>
文件
In BundleConfig:
bundles.Add(new Bundle("~/templates/handlebars").IncludeDirectory("~/Templates", "*.html", true));
增加了以下RazorExtension:
public static class RazorExtensions
{
public static IHtmlString RenderTemplates(this HtmlHelper htmlHelper, string src)
{
var context = htmlHelper.ViewContext.HttpContext;
if (string.IsNullOrEmpty(src) || context == null || context.Request.Url == null)
{
return null;
}
using (WebClient Client = new WebClient())
{
var request = context.Request;
var url = request.Url.Scheme + "://" + request.Url.Authority + Scripts.Url(src).ToHtmlString();
var content = Client.DownloadString(url);
return new MvcHtmlString(content);
}
}
}
在我的剃须刀页:
@Html.RenderTemplates("~/templates/handlebars")
是的,谢谢。该文章中的代码将模板或任何其他内容进行组合。但它不会像Cassette那样将它们编译为JavaScript。 –