获取iframe后显示的URL无法正确显示

时间:2013-06-15 14:44:24

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

我在ASP.Net MVC4中使用EF正确地将URL保存到数据库中:
URL如下所示:

 www.abc.com?id=a&name=value

但是当我找回它时尝试在iframe中显示为src然后

 & is converted to &

示例:

<iframe width="500" height="400" src="www.abc.com?id=a&amp;amp;name=value">

如何显示确切的网址? 如下所示:

   src="www.abc.com?id=a&name=value"

1 个答案:

答案 0 :(得分:1)

选项#1

您在保存到数据库时检索数据和HttpUtility.HtmlDecode时是否使用HttpUtility.HtmlEncode

代码示例

string value1 = "&lt;html&gt;";
string value2 = HttpUtility.HtmlDecode(value1);   //<html>
string value3 = HttpUtility.HtmlEncode(value2);   //&lt;html&gt;

选项#2

使用HttpUtility.HtmlEncode将数据保存在数据库中后,您可以Html.Raw使用Decode,如下所示。

代码示例

@Html.Raw("&lt;html&gt") //gives <html>