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
-
1String values need to be wrapped in quotes...David– David2015年06月11日 12:40:11 +00:00Commented Jun 11, 2015 at 12:40
3 Answers 3
try to this
var jsNotes1 ='@Model.Notes1';
Comments
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
Try this is in javascript...
var jsNotes1= @Html.Raw(Json.Encode(Model.notes1));
Comments
Explore related questions
See similar questions with these tags.