将razor C#字符串转换为jQuery字符串

时间:2018-11-01 07:49:37

标签: jquery asp.net-mvc razor

当我将此代码用作脚本时,我在控制台中收到此错误:

  

语法错误:缺少变量名

$(document).ready(function () {
        var multiselect = $("#TahiyeKonande").data("kendoMultiSelect");
        var arr = [];
        var t = @ttt;
        var tt = t.split(",");
        console.log(tt);
        // set the value of the multiselect.
        console.log(arr);
        multiselect.value(arr);
    });

1 个答案:

答案 0 :(得分:4)

要将razor viewbag字符串转换为js,请使用双引号

$(document).ready(function () {
        var multiselect = $("#TahiyeKonande").data("kendoMultiSelect");
        var arr = [];
        var t = "@ttt";
        var tt = t.split(",");
        console.log(tt);
        // set the value of the multiselect.
        console.log(arr);
        multiselect.value(arr);
    });