这就是我用于车把模板的内容
模板示例:位于 ~/Templates/template123.html 中的文件
<script id="template123" type="text/html">
<div>someTemplate</div>
</script>
在 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")