title: Encapsulate JavaScript completely in partial view (jQuery Widgets/ASP.NET MVC example)
body: <p>I've started using jQuery Widgets and I want to populate a DataTable with JSON data. This is my code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          // prepare the data
          var url = '@Url.Action("AjaxGetNewsItems", "News")';
          console.log(url);
  
          var source =
          {
              dataType: "json",
              dataFields: [
                  { name: 'title'},
                  { name: 'text'},
                  { name: 'id'}
              ],
              url: 'News/AjaxGetNewsItems'
              //id: 'id'
          };
          var dataAdapter = new $.jqx.dataAdapter(source);
  
          console.log(dataAdapter);
  
          $("#dataTable").jqxDataTable(
          {
              width: 850,
              source: dataAdapter,
              theme: 'arctic',
              pageSize: 5,
              sortable: true,
              filterable: true,
              pageable: true,
              columns: [
                  { text: 'title', dataField: 'title', width: 300 },
                  { text: 'text', dataField: 'text', width: 200 },
                  { text: 'id', dataField: 'id', width: 200 }
              ]
          });
      });
  &lt;/script&gt;
  
  
  &lt;div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;overflow: display; padding-top: 20px;"&gt;
      &lt;div id="dataTable"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is what my JSON looks like:</p>
  
  <pre><code>[
      {
          "title": "Tree fungus ID: Inonotus dryadeus",
          "text": "Ref: 204201/252874\r\nThe fruiting bodies are those of a fungus called Inonotus dryadeus. Oak is the most common host of this fungus, which can often cause decay of the inner parts of the root system and the base of the trunk.\r\n\r\nWhilst the fungus can cause extensive decay, the effect on the tree itself can be very variable. Some trees will survive for many years or even indefinitely - although the central roots and wood may decay the hollow tree remains alive and standing on 'stilts' of buttress roots. However, if the decay also affects these roots then there is a risk of the tree falling. In a case such as this we would always recommend having the tree examined in situ by an arboricultural consultant, particularly if there is any risk of injury or damage to property should the tree fall. The consultant will be able to check the location and extent of the decay, and recommend any appropriate remedial action (such as crown reduction).\r\n\r\nThe link below takes you to our web profile on bracket fungi. This does not mention Inonotus dryadeus specifically, but gives the contact details for the Arboricultural Association who will be able to provide you with a list of suitably-qualified consultants operating in your area. \r\n\r\nhttp://apps.rhs.org.uk/advicesearch/Profile.aspx?pid=98\r\nI hope this information is helpful.\r\nYours sincerely, \r\nJohn Scrace\r\nPlant Pathologist",
          "id": 6
      }
  ]
  </code></pre>
  
  <p>Finally my console window of dataAdapter:</p>
  
  <p><img src="https://i.stack.imgur.com/9cCpH.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/HFNKE.png" alt="enter image description here"></p>
  
  <p>What am I doing wrong?</p>