【问题标题】:Razor template containing page parts that mustache will render on clientRazor 模板包含 mustache 将在客户端呈现的页面部分
【发布时间】:2016-02-13 11:02:19
【问题描述】:

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

我遇到的问题是剃须刀没有像我期望的那样渲染零件。例如:

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

不会渲染 ~ 符号,只有当我将 img 放在脚本标签之外时,它才会按预期执行。

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

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 razor-2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 1970-01-01
      相关资源
      最近更新 更多