Razor template containing page parts that mustache will render on client

寵の児 提交于 2019-12-11 12:25:40

问题


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>

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.


回答1:


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>


来源:https://stackoverflow.com/questions/33666065/razor-template-containing-page-parts-that-mustache-will-render-on-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!