title: How to access a json object in javascript files from a model passed to the view
body: <p>I have a JSON object in my database that contains html inside it. I pass the object as part of a model to my view. I need to access the object and read it in the javascript files for the page. However when i try and assign the object to a global variable in my html file i cannot access it in my javascript file.</p>
  
  <p>I tried reading the object as a string it returns decoded html (&#xD;&#xA;&#x9;&quot;page-1&quot;:) which i cant do anything with. If i call @Html.Raw(@Model.CourseContent.ExpectedResult) it created the JSON object as expected. However in my javascript file it is listed as undefined. I have no idea how to solve this.</p>
  
  <pre><code>@model DataTransferObjects.Models.UserCourseAndContent
  &lt;script&gt;
      var totalPages = '@Model.CourseContent.TotalPages';
      var expectedResults = @HTML.Raw(@Model.CourseContent.ExpectedResult)
  
  &lt;/script&gt;
  </code></pre>
  
  <p>
      </p>
  
  <p>The json object that comes out when i use the above code looks like </p>
  
  <pre><code>var expectedResults = {
      "page-1": "&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;",
      "page-3": "&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;My Cool News Article&lt;/h1&gt;&lt;p&gt;Welcome 
                      to my news article, you’ll find some cool news here.&lt;/p&gt; 
      &lt;Our most recent 
      news&lt;/&lt;p&gt;Below you’ll find my most recent news!&lt;/p&gt;&lt;/body&gt;"
      };
  </code></pre>
  
  <p>I expected it to be an actual json string but instead ive got an object (?) i am confused as to how to decode the html out of it then turn the resulting json obejct into a json string to be read in the javascript file.
  Any help would be great!</p>