Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在html/asp.net-mvc中,在图像工具提示中包含撇号的正确方法是什么_C#_Html_Asp.net Mvc_Image_Apostrophe - Fatal编程技术网

C# 在html/asp.net-mvc中,在图像工具提示中包含撇号的正确方法是什么

C# 在html/asp.net-mvc中,在图像工具提示中包含撇号的正确方法是什么,c#,html,asp.net-mvc,image,apostrophe,C#,Html,Asp.net Mvc,Image,Apostrophe,如果我有从数据库表填充的图像工具提示。我从服务器端的C#代码生成下面的html 公共字符串GetImage() { 返回“”; } 问题在于,如果变量dataIssue中有撇号,则它只显示字符串中截至该点的字符 鉴于上述代码,在工具提示中显示整个字符串的最佳方式是什么?”不是HTML的特殊符号,浏览器显示整个字符串时不会出现问题,但您可能会遇到以下符号的问题“&应将其转义为: " < > & 如果您的浏览器不正确地对待HTML标准

如果我有从数据库表填充的图像工具提示。我从服务器端的C#代码生成下面的html

公共字符串GetImage()
{
返回“”;
}
问题在于,如果变量dataIssue中有撇号,则它只显示字符串中截至该点的字符


鉴于上述代码,在工具提示中显示整个字符串的最佳方式是什么?

不是HTML的特殊符号,浏览器显示整个字符串时不会出现问题,但您可能会遇到以下符号的问题
“<>&
应将其转义为:

&quot;
&lt;
&gt;
&amp;
如果您的浏览器不正确地对待HTML标准并剪切了字符串的其余部分,您可以尝试使用
';
来转义单引号-这将适用于所有浏览器

因此,根据HTML标准,属性值应该被
符号包围,而不是被
包围,因此这里的问题应该得到解决:

dataIssue = any_kind_of_html_escape_function_here(dataIssue);
return "<img class=\"iconSpace\" title=\"" + dataIssue + "\" src=\"/Content/Images/Icons" + size + "/information_red.png\" />";
dataIssue=此处的任何类型的函数(dataIssue);
返回“”;

对于asp.net,此处定义了htmlencode函数:

这对您有用吗

string img = "<img class=\"iconSpac\" title=\"" + dataIssue + "\" " + "scr=\"/Content/Images/Icons\"" + size + "/information_red.png\" />";

string img=“您应该使用
HttpUtility.HtmlEncode(“…”)


我更新了问题以更好地突出根本问题。。请随意删除您的答案。@leora答案与您的更新更相关,同时检查正确的代码
string img = "<img class=\"iconSpac\" title=\"" + dataIssue + "\" " + "scr=\"/Content/Images/Icons\"" + size + "/information_red.png\" />";