ASP.net 文字或页面更改 HTML 字符串,导致格式问题
我们有一项服务可以生成报告(使用 Word 模板和第 3 方库),然后返回 HTML 格式的字符串。虽然这个 HTML 不太好 - 它在这个字符串中的格式正确。
我们希望此 HTML 以完整的格式显示在页面上。我们当前所做的是将 ASP.net Literal 的文本元素设置为此字符串。
虽然这有效,但我注意到它稍微重新格式化了 HTML 字符串。在大多数情况下,看起来它生成了一堆新的 CSS 类,以及 HTML 中的新样式元素。返回的字符串中不存在此 HTML。我可以将所有这些过滤掉,但想知道是否有更好的方法。
我认为页面本身正在改变一些东西。
向用户显示原始 HTML 的最佳方式是什么?我不能直接使用 Response.Write(string),因为此页面上确实有一些其他控件。
We have a service that generates a report (using word templates and a 3rd party library), and then returns a string in HTML. While this HTML isn't great - its formatted correctly in this string.
We want this HTML to show up on a page - format intact. What we currently have done is set an ASP.net Literal's text element to this string.
While this works, I have noticed that it has reformatted the HTML string slightly. For the most part, it looks like it generated a bunch of new CSS classes, and a new style element in the HTML. This HTML does not exist in the string thats being returned. I could filter all of this back out, but wonder if there is a better way.
I assume that the Page itself is altering something.
What is the best way to display this raw HTML back to the user? I can't directly use a Response.Write(string), because this page does have a few other controls on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文字控件不会格式化它们的文本值(AFAIK),所以我猜它是别的东西。可能是一个响应过滤器(Request.Filter)可以改变页面输出?另一种可能性可能是包含控件可能会在其自定义呈现中更改其子控件的值(即您的文字)。
Literal controls do not format their text values (AFAIK), so I would guess it's something else. Possibly a response filter (Request.Filter) which could be altering the page output? Another possbility may be that a containing control might be altering the value of its child controls (i.e. your literal) in it's custom rendering.
我没有听说过 Literal 控件的行为方式与您所描述的方式相同,并且每当我使用它时都没有看到它的行为方式,但我以前没有尝试过以这种方式输出 html。
另一种方法是将 html 分配给代码隐藏文件中的公共页面属性,然后在 aspx 文件中使用服务器端脚本标记来显示该属性的内容:
I've not heard of the Literal control behaving the way you have described and not seen it behave that way whenever I have used it but I have not attempted to output html in this way before.
An alternative could be to assign the html to a public page property in your code behind file and then use server side script tags in your aspx file to display the contents of this property:
这是我自己的错误,第三方库的设置。在我的比较页面弄乱 CSS 之前,我正在保存它。不过,谢谢您的有用回答 - 我以为我失去了理智!
It was my own mistake, a setting on the third party library. I was saving my comparison page before it was messing with the CSS. Thank you for your helpful answers though - I thought I was loosing my mind!