在 Asp.Net 模板中转义内联代码块
我有一个页面,我希望在其中呈现以下 html(一个小型 JS 模板) -
<script type="text/html" id="lightbox-template">
<div id="lightbox-background"></div>
<div id="lightbox"><%= content %><div class="bottom"></div></div>
</script>
但是,Asp.NET 预处理器正在拾取“<%=”标记并尝试解释它。我希望转义这个标签以允许它被渲染,最好是从模板而不是后面的代码。这可能吗?
我已经设法通过文字控件来做到这一点,并在后面的代码中设置它的文本。
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>
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?
I have managed to do this via a Literal control and setting it's text in the code behind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我理想地希望将其保留在 aspx 页面中。这是我能找到的最佳解决方案(从这里),它创建分割结束>到一个单独的字符串
重要位:<%= "<%= content %" + ">" %=>
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
Important bit: <%= "<%= content %" + ">" %=>
这进入 aspx
这进入 aspx.cs
This goes into aspx
This goes into aspx.cs