如何使用C#将html文件从数据库预览到浏览器
本文关键字:数据库 浏览器 文件 何使用 html | 更新日期: 2023-09-27 18:24:28
我将HTML代码存储在数据库中,并希望将其显示(呈现)到视图中。
我想把它显示为普通的文本页。
eg: **HTML:** <h3 style="font-weight: bold">Usage:</h3>
<p style="text-decoration: underline">Viewing of Form -</p>
Should be shown as: Usage:
Viewing of Form -
我有一个按钮作为视图,当点击时,它应该会显示页面。
我正在使用实体框架工作,所以我已经写了,
string url = ("view.aspx?id = " + page.ID + "&Text=" + page.Text);
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + url + "', null, 'height=500,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=yes' );", true);
我创建了一个新的页面view.aspx,并尝试使用System.Web.HttpUtility.HtmlDecode(Request.QueryString["Text"])
来呈现该文件。
但我收到了一张空白页。
请帮帮我。
谢谢,
您能确认page.Text
在渲染时有一个值吗?
如果您确信值page.Text
填充正确(我假设类似于"view.aspx?id=1&Text=<h3>example post<h3>"
),那么在将URL返回到客户端之前,您可能需要尝试对其字符串进行编码。
string url = ("view.aspx?id = " + page.ID + "&Text=" + System.Web.HttpUtility.UrlEncode(page.Text));
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + url + "', null, 'height=500,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=yes' );", true);
然后确保在客户端的链接中获得编码字符。