1

I am trying to read model variable in jquery ready function.

 var jsNotes1 [email protected];

when the model.notes1 has an integer value, I was having no issues. But when the model.notes1 has a string value, say for ex: "abcd", the line is getting converted as below

var jsNotes1 = abcd

and Jquery is assuming abcd as a variable rather than as string value and is throwing reference error that abcd is not defined.

Please help me if i am missing something here

1
  • 1
    String values need to be wrapped in quotes... Commented Jun 11, 2015 at 12:40

3 Answers 3

3

try to this

var jsNotes1 ='@Model.Notes1';
Sign up to request clarification or add additional context in comments.

Comments

1

You need to wrap it in quotes as it needs to be treated as a string, otherwise it's invalid JavaScript

var jsNotes = "@Model.Notes1";

Comments

0

Try this is in javascript...

var jsNotes1= @Html.Raw(Json.Encode(Model.notes1));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.