1

大家好,我在我的 javascript 中使用以下语法

 var careteam = "@Html.Raw(Json.Encode(Model.CareTeamForFile))";

我收到以下错误

SyntaxError: missing ; before statement
[Break On This Error]   

var careteam = "[{"GroupId":3,"GroupName":"Physician","Users":[{"UserId":3438,"

那里有一个箭头指示位置。

我在其他地方使用过这种语法,它工作得非常好。

4

1 回答 1

2

在 JS 中,你得到下一行:

var careteam = "[{"GroupId":3,"GroupName":"Physician","Users":[{"UserId":3438,"

如果我们阅读这一行,它会为您提供变量声明var careteam = "[{",在您拥有GroupId":3,"GroupName":"Physician","Users":[{"UserId":3438,"这对 JS 没有意义之后。

将剃刀语法更改为:

var careteam = '@Html.Raw(Json.Encode(Model.CareTeamForFile))';

所以在careteam你会有一个字符串

var careteam = '[{"GroupId":3,"GroupName":"Physician","Users":[{"UserId":3438," ... '

但我敢打赌这不是你想要的,你想在 中有一个数组careteam,所以我猜这是正确的解决方案:

var careteam = @Html.Raw(Json.Encode(Model.CareTeamForFile));

你会得到 JS:

var careteam = [{"GroupId":3,"GroupName":"Physician","Users":[{"UserId":3438," ... 
于 2013-04-07T18:36:21.673 回答