单引号在c#string中用双引号括起来
问题描述:
亲爱的所有人,
我在c#代码中遇到问题,分配到下面的字符串,但它不适合使用单引号。
Dear All,
I am getting problem in c# code to assign below string but its not proper working with single quotes.
string HighSlide = @"<a style='border: none;' href='CompanyMaster.aspx?popup=true'<br />
önclick='return hs.htmlExpand(this, { objectType: 'iframe', align: 'left', width: 810, height: 520 });'><br />
" + e.Day.Date.Day + "</a>";
当我在浏览器上看到这一行时,它会生成如下字符串。
When I see this line on browser it generate like below string.
string HighSlide = @"<a style='border: none;' href='CompanyMaster.aspx?popup=true'
önclick='return hs.htmlExpand(this, { objectType: " + "''" + @"iframe" + "\'" + @", align: " + "\'" + @"left" + "\'" + @", width: 810, height: 520 });'>
" + e.Day.Date.Day + "</a>";
请帮助纠正同样的问题。
先谢谢你。
Please help to correct for the same.
Thank you in advanced.
答
您需要用双引号替换onclick中的单引号(如先前Timberbird建议的那样)或用双引号替换对象文字中的单引号。如果您在HTML文档中对此片段进行硬编码,情况也是如此。
You need to either replace the single quotes from onclick with double quotes (as previously suggested by Timberbird) or replace the single quotes in the object literal with double quotes. The same would be true if you hard-coded this snippet in an HTML document.
亲爱的所有人,
我得到了解决方案,因为我使用了&#39我收到错误时的前缀和后缀。
示例:&#39frame&#39它将自动生成类似'frame'。
非常感谢你的帮助。
Dear All,
I got the solution as I used ' prefix and suffix when I got the error.
example : 'frame' Its will automatically generate like 'frame'.
Thank You very much for your help.