C# 如何使用实体框架保存包含HTML标记的字符串?

C# 如何使用实体框架保存包含HTML标记的字符串?,c#,html,entity-framework,C#,Html,Entity Framework,我想使用实体框架保存一个包含HTML标记的字符串,但它不起作用。以下是我要保存到数据库中的字符串: 这是我的文本您可以使用HTML编码和解码 在将字符串插入数据库之前,只需对其进行html编码。所以你的绳子会变成这样 <p><span style="color:#FF0000"><span style="background-color:#00FFFF"

我想使用实体框架保存一个包含HTML标记的字符串,但它不起作用。以下是我要保存到数据库中的字符串:


这是我的文本

您可以使用HTML编码和解码

在将字符串插入数据库之前,只需对其进行html编码。所以你的绳子会变成这样

<p><span style="color:#FF0000"><span style="background-color:#00FFFF">This is my text</span></span></p>
从数据库读取数据时,只需解码字符串

插入:

string toInsert = "<b>some html tags</b>";
encodedString = Server.HtmlEncode(toInsert); 
// encodedString is &lt;b&gt;some html tags&lt;/b&gt;

// insert into the database
string toInsert=“一些html标记”;
encodedString=Server.HtmlEncode(toInsert);
//encodedString是b一些html标记/b
//插入到数据库中
阅读:

string readFromDatabase = // read from database;
string originalString = Server.HtmlDecode(readFromDatabase);
// originalString is "<b>some html tags</b>"
string readFromDatabase=//从数据库读取;
string originalString=Server.HtmlDecode(readFromDatabase);
//原始字符串是“一些html标记”

您可以使用HTML编码和解码

在将字符串插入数据库之前,只需对其进行html编码。所以你的绳子会变成这样

&lt;p&gt;&lt;span style=&quot;color:#FF0000&quot;&gt;&lt;span style=&quot;background-color:#00FFFF&quot;&gt;This is my text&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
从数据库读取数据时,只需解码字符串

插入:

string toInsert = "<b>some html tags</b>";
encodedString = Server.HtmlEncode(toInsert); 
// encodedString is &lt;b&gt;some html tags&lt;/b&gt;

// insert into the database
string toInsert=“一些html标记”;
encodedString=Server.HtmlEncode(toInsert);
//encodedString是b一些html标记/b
//插入到数据库中
阅读:

string readFromDatabase = // read from database;
string originalString = Server.HtmlDecode(readFromDatabase);
// originalString is "<b>some html tags</b>"
string readFromDatabase=//从数据库读取;
string originalString=Server.HtmlDecode(readFromDatabase);
//原始字符串是“一些html标记”

有关详细信息,您是否看到了“EntityValidationErrors”属性?我看到了,但我想将数据保存到此处的实体。谢谢。有关更多详细信息,您是否看到了“EntityValidationErrors”属性?我看到了,但我想将数据保存到此处的实体。谢谢,我很抱歉,这没用,我试过用html编码。当我调试时,值为
pspan style=“color:#FF0000”span style=“background color:#00FFFF”这是我的文本/span/span/p
,但它没有保存在实体框架中。对于一个或多个实体,仍然存在错误
验证失败。有关详细信息,请参阅“EntityValidationErrors”属性。
。请检查“EntityValidationErrors”的值,并告诉我们哦,我很抱歉,它不起作用,我尝试了html编码。当我调试时,值为
pspan style=“color:#FF0000”span style=“background color:#00FFFF”这是我的文本/span/span/p
,但它没有保存在实体框架中。对于一个或多个实体,仍然存在错误
验证失败。有关更多详细信息,请参阅“EntityValidationErrors”属性。请检查“EntityValidationErrors”的值并告知我们