Question

I am passing an array from my MVC5 EF6 controller to the view. When I assign the object to a javascript var, the compiler issues a 314: sytax error. The code works fine, so it is not a big deal however, I cannot publish my webapp because of it. I have to exclude the offending view and then publish separately. The pesky line of code causing this trouble is:

var sizeArray = @(Html.Raw(Json.Encode(@ViewBag.Sizes)));

Enclosing the thing in quotes doesn't help because JSON.parse throws a fit of illegal characters. Help is appreciated and will be be up-arrowed and marked as a solution.

Was it helpful?

Solution

There seems to be little interest, maybe because I am using VS2013 RC1. In any case, I have found the solution. If it helps you, give me an up arrow.

var sizeArray = new Object(@(Html.Raw(Json.Encode(@ViewBag.Sizes))));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top