1

I seem to be having an issue with using razor syntax within a javascript block. The following compiles, however, I'm getting a syntax error warning.

An example of when this happens:

@section scripts{
    <script type="text/javascript">
        var rating = @Model.Rating;
    </script>
} 

1 Answer 1

3

That's a false positive from the editor, which doesn't recognize Razor in JS.
Ignore it.

However, if you use this approach for textual data, make sure to Javascript-escape it, or ou will get runtime JS errors & XSS vulnerabilities.

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.