2

I am trying to bind a model object to a javascript array:

<script type="text/javascript">
    var tests = [];
    tests = @Html.Raw(new JavaScriptSerializer().Serialize(Model.TestList));
</script>

I get a small red syntax-error marker under the semicolon. If I remove the semicolon, I get the same red marker in the next line. This is inside a partial view inside the last div just before the </div> tag.

What am I missing in this piece of code?

1
  • 1
    This is just an issue with intellisense; it won't actually generate a runtime error in your JavaScript. Commented Jul 12, 2013 at 21:21

1 Answer 1

4

Try it this

 tests = @(Html.Raw(new JavaScriptSerializer().Serialize(Model.TestList)))

semicolon not required in the end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.