我有一个函数可以为我生成 JavaScript 代码。
<img src="abc.png" alt="hello" onclick="<%: getOnCilckJS(arg) %>" />
C# 代码
protected String getOnCilckJS(int arg)
{
if (arg==1)
{
return "alert('hello world');";
}
else
{ return "alert('hello universe');";
}
}
除了页面加载时 asp.net 将单引号 '
转换为编码的 html 字符串 ('
)
如何避免这种情况并使 '
出现在 html 中?
最佳答案
您的应用程序是 Web Forms 还是 MVC?
如果是MVC可以尝试Html.Raw(...)函数,如果是Web Forms可以查看这个link .
关于c# - 如何在输出到html之前停止asp.net编码字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19445196/