So, I have a some json data which I create in my controller like so:
Notes = JsonConvert.SerializeObject(contact.Notes.OrderBy(x => x.DateLogged).Select(x => new
{
id = x.Id,
date = x.DateLogged,
content = x.Content,
logged = x.Username
}))
This then gets passed to the view, now which statment can I do to achieve the results of having a variable contain that json data:
var data = '@Html.Raw(Model.Notes)'
or
var data = JSON.parse('@Html.Raw(Model.Notes)');
EDIT
the content variable holds some "\n" which when passed to the view using the first choice from above generates an error, saying
Unexpected Token
it only does it with \n so what is going wrong here? the bottom method doesn't quite work.
JSONlibrary doesn't like\n, if i got with the top method with no parse then it works finevar data = '...<newline>...and the Javascript parser itself is the one complaining about that newline. You need to escape it somehow. I assume @Html.Raw is meant to be put inside of HTML, not inside of a<script>tag.