包含页面部分剃刀模板胡须会使客户端 [英] Razor template containing page parts that mustache will render on client

查看:79
本文介绍了包含页面部分剃刀模板胡须会使客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My page contains parts that will render on the client.

我遇到的问题是,如剃刀我希望他们不会呈现的部分。例如:

The problem I'm having is that razor does not render the parts as I expect them to. For example:

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

将不渲染标志,只有当我把的img脚本标记之外将它做预期。

Will not render the ~ sign, only when I place img outside of the script tags will it do as expected.

这是发表在不同的应用程序路径所以我需要剃刀找出是与应用程序路径替换它。

This is published in different application paths so I need razor to figure out what ~ is and replace it with the application path.

推荐答案

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

You should use @Url.Content helper which will correctly resolve the path relative to the application root:

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

这篇关于包含页面部分剃刀模板胡须会使客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆