I found in this link a solution to transfer some data from my model to a javascript object. The problem is that I have an error in visual studio indicating that the semi-colon is invalid but when I try to run my application, it works perfectly.
Here is a screenshot that show the error:

But if I remove the semi-colon, I now have this error:

In anyways, a javascript statement should always have a semi-colon at the end of the line.
What means this error if when I run my application, all works fine?
You might try enclosing it in a block:
var serializedData = @{
Html.Raw(NewtonSoft.Json.JsonConvert.SerializeObject(Model));
};
Edit: This answer only applies to VS 2010. An upgrade in VS 2012 breaks this workaround as well.
I am just starting with Razor/MVC4, but can you so something like this?
@{
var serializedData = Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
}
<script>
...
var serializedData = @serializedData;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With