下面的代码是生成& quot而不是正常的引号,导致javascript错误地读取我的asp变量。我甚至http实用程序解码它和同样的问题。
@{
string labels = "";
foreach (var item in Model)
{
labels = labels + "\"" + item.Month + "\",";
}
labels = labels.TrimEnd(',');
}
var salesChartData = {
labels: [@labels],
datasets: [
标签出现了
labels: ["April","July","February","May","June","March"]
答案 0 :(得分:2)
默认情况下,Razor对页面上输出的所有内容进行HTML编码,包括引号。要强制原始输出,请使用Html.Raw:
labels: [@Html.Raw(labels)],