Gratzy
Gratzy

Reputation: 2898

Knockout syntax error warning but it still works

Can anyone shed any light on this? I'm getting a compiler warning in VS2013/C# on this line but yet it still works....

SendData = ko.toJSON({
    UserName: @Html.Raw(Json.Encode(Model.UN)),
    Notes: self.Notes,
    nRecID: @Html.Raw(Model.pkRecID),
    AddColors: self.AddColors
})

The warnings are on the commas between the elements. All the compiler says is, "Syntax error".

Upvotes: 0

Views: 62

Answers (1)

PatrickSteele
PatrickSteele

Reputation: 14677

It's just a side-effect of mixed client-side and server-side code. Visual Studio knows that the @Html.Raw(...) is server-side code so it ignores it when parsing your client-side javascript. So what Visual Studio sees is:

SendData = ko.toJSON({ UserName: , Notes: self.Notes, nRecID: , AddColors: self.AddColors })

As you can see, that isn't valid javascript since you're not providing a value for UserName or nRecID. Anyway, you can safely ignore it.

Upvotes: 1

Related Questions