在mvc视图中,javascript中的引号无法正确呈现 [英] Quotes not rendering properly in javascript in mvc view
问题描述
我在部分视图中有一个如下所示的脚本标记:
I have a script tag like below in my partial view :
<script>
$(function () {
$.ajax({
type: "GET",
url: "/api/ChartsAPI/2",
dataType: "json",
success: function (seriesData) {
console.log(seriesData);
$("#chart").kendoChart({
dataSource: {
data: seriesData
},
series: [{
field: "yaxisData",
name: "Average"
}],
title:
{ @ViewBag.PlaceHolder }
});
}
});
})
</script>
在我的控制器中,视图包数据填充如下:
In my controller the view bag data is populated like below :
ViewBag.PlaceHolder = "text:'test'";
但是使用此配置,图表无法正确呈现为标题的图表文本呈现如下:
But with this configuration, the chart is not getting rendered correctly as the chart text for the title is being rendered as below :
text:'test'
如何摆脱javascript中qutoes的ascii。
How to get rid of the ascii for the qutoes in javascript.
推荐答案
(function(){
(function () {
.ajax({
类型:GET,
url:/ api / ChartsAPI / 2,
dataType:json,
成功:函数(seriesData){
console.log(seriesData);
.ajax({ type: "GET", url: "/api/ChartsAPI/2", dataType: "json", success: function (seriesData) { console.log(seriesData);
(#chart)。kendoChart({
dataSource:{
data:seriesData
},
系列:[{
字段:yaxisData,
名称:平均
}],
标题:
{@ ViewBag.PlaceHolder}
});
}
});
})
< / script>
("#chart").kendoChart({ dataSource: { data: seriesData }, series: [{ field: "yaxisData", name: "Average" }], title: { @ViewBag.PlaceHolder } }); } }); }) </script>
在我的控制器中,视图包数据的填充方式如下:
In my controller the view bag data is populated like below :
ViewBag.PlaceHolder = "text:'test'";
但是使用此配置,图表无法正确呈现,因为标题的图表文本呈现如下:
But with this configuration, the chart is not getting rendered correctly as the chart text for the title is being rendered as below :
text:'test'
如何摆脱javascript中qutoes的ascii。
How to get rid of the ascii for the qutoes in javascript.
这篇关于在mvc视图中,javascript中的引号无法正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!