简体   繁体   English

在数据库查询字符串中启用HTML标记

[英]Enable HTML Tag inside DB Query String

I have a database query that displays a string: 我有一个显示字符串的数据库查询:

db.query.record

"This is a string" “这是一个字符串”

I want the string to be read: 我想读取字符串:

"This “这个
is
a 一种
string" 串”

the code i used was db.query.record.replace(" ", "<br />") and the results i got were: 我使用的代码是db.query.record.replace(" ", "<br />") ,得到的结果是:

"This <br> is <br> a <br> string" “此<br><br>一个<br>字符串”

What i understand is, the replace syntax is storing the html tag in the database string before it is read. 我了解的是, replace语法是在读取HTML标记之前将其存储在数据库字符串中。 After it is read, anything inside the string is displayed just as it is stored (as a string). 读取后,字符串内部的任何内容都会按其存储方式(作为字符串)显示。 I need the html to bypass the string, and fetch the html tag, and perform the action. 我需要html绕过字符串,并获取html标记并执行操作。

Suggestions, ideas? 建议,想法? I've tried everything... and all results i've tried were done to the text string... and not to the actual html. 我已经尝试了一切...我尝试的所有结果都完成了文本字符串...而不是实际的html。 Be mindful that i dont need this to affect the entire document, just the queried data. 请注意,我不需要这个来影响整个文档,而只是查询的数据。 I need it to be multi-line, because the data is making my page disorganized (text vary in lengths and size) 我需要将其设置为多行,因为数据使我的页面混乱(文本的长度和大小不同)

If there are any answers that cover the topic Literals or LiteralsControl can you please include extra details, cause either i dont understand enough or it, or i was doing it wrong. 如果有任何涉及LiteralsLiteralsControl主题的答案,您可以提供更多详细信息吗,原因可能是我不够了解,或者是我做错了。 Internet queries does not provide enough understanding for me. 互联网查询无法为我提供足够的了解。

I want to perform the complete opposite of this request: overflow-link 我要执行与此请求完全相反的操作: overflow-link

I know I've personally had trouble with this, but on a web page. 我知道我个人对此有麻烦,但是在网页上。 So, I'm assuming you're trying to add content to your page. 因此,我假设您正在尝试向页面添加内容。

If you're adding the text to, let's say, a <p> tag, you'll need to set the text via .innerHTML as opposed to .innerText . 如果要将文本添加到<p>标记中,则需要通过.innerHTML而不是.innerText来设置文本。

Example: 例:

HTML: HTML:

<p id='myP' runat='server'>Test</p>

VB: VB:
myP.innerHTML = db.query.record.replace(" ", "<br />");
Or 要么
myP.Controls.Add(New LiteralControl(db.query.record.replace(" ", "<br />")));

The answer was from another overflow question: .Replace(Environment.NewLine, "<br />") works on localhost but not when I upload my website to host 答案来自另一个溢出问题: .Replace(Environment.NewLine,“ <br />”)在localhost上有效,但是当我将网站上传到主机时无效

@Html.Raw(Html.Encode(Model.Body)
.Replace(Environment.NewLine, "<br />"))<br />

i simply changed out Model.Body with db.query.record and Environment.NewLine with " " . 我只是用db.query.recordEnvironment.NewLine" "更改了Model.Body Apperently, that did the trick. 显然,这可以解决问题。 What i discovered was that encoding/decoding the string was my issue, but it just wasnt applying at the right stage. 我发现是对字符串进行编码/解码是我的问题,但是它并没有在正确的阶段应用。 It was supposed to be done a period after it was compiled, but before it was read (by the browser). 它应该在编译之后但在(由浏览器)读取之前的一段时间内完成。 I'm not sure, something like that... Anyways, i understand what i did wrong, and i figured it out. 我不确定,是那样的...无论如何,我了解自己做错了什么,并且我知道了。 Thanks to those that submitted. 感谢那些提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM