包含 mustache 将在客户端呈现的页面部分的 Razor 模板

Razor template containing page parts that mustache will render on client

我的页面包含将在客户端呈现的部分。

我遇到的问题是剃须刀没有按照我的预期渲染零件。例如:

<script type="x-tmpl-mustache" id="filterTemplate">
        <img id="showFilter" src="~/Content/Image/arrow.png" />
</script>

不会呈现 ~ 标志,只有当我将 img 放在脚本标签之外时,它才会按预期运行。

这是在不同的应用程序路径中发布的,所以我需要 razor 弄清楚 ~ 是什么,并将其替换为应用程序路径。

您应该使用 @Url.Content 助手,它将正确解析相对于应用程序根目录的路径:

<script type="x-tmpl-mustache" id="filterTemplate">
        <img id="showFilter" src='@Url.Content("~/Content/Image/arrow.png")' />
</script>