2

I have following line of code inside my js function saved as separate js file

 $('#Page').val(@Html.Raw(Json.Encode(Model.MyFormats));

on page loading inside firebug console I'm getting following error

SyntaxError: illegal character

with pointer to @ inside @Html.Raw...

1 Answer 1

6

Razor code is not parsed in external files. You need to assign the value of @Html.Raw(Json.Encode(Model.MyFormats) to a javascript variable in the main view and pass it to your external script (for example, assign it to a global variable and then use $('#Page').val(myFormats);)

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.