逃离直列code在Asp.Net模板块 [英] Escaping inline code block in Asp.Net template

查看:151
本文介绍了逃离直列code在Asp.Net模板块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我想呈现以下HTML(小JS模板) -

I have a page where I wish to render the following html (a small JS template)-

<script type="text/html" id="lightbox-template">
 <div id="lightbox-background"></div>
 <div id="lightbox"><%= content %><div class="bottom"></div></div>
</script>

不过,Asp.NET preprocessor是在捡&LT;%=标签,并试图间preT它。我想逃离这个标签允许它被渲染,preferably从模板,而不是code后面。这可能吗?

However, the Asp.NET preprocessor is picking up on the "<%=" tag and trying to interpret it. I wish to escape this tag to allow it to be rendered, preferably from the template rather than the code behind. Is this possible?

我设法通过文字控制做到这一点,设置它在code后面的文本。

I have managed to do this via a Literal control and setting it's text in the code behind.

推荐答案

我最好要保持它的aspx页面内。这是我能找到的最好的解决方案(从这里),创建拆分结束>到一个单独的字符串

I ideally wanted to keep it within the aspx page. This is the best solution I could find (from here), which creates splits the closing > into a separate string

<script type="text/html" id="lightbox-template">
 <div id="lightbox-background"></div>
 <div id="lightbox"><%= "<%= content %" + ">" %=><div class="bottom"></div></div>  
</script>

重要的一点:&LT;%=&LT;%=含量%+> <%=>

这篇关于逃离直列code在Asp.Net模板块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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