title: Cannot call external Javascript method
body: <p>I am using an external Javascript file from an MVC 5 web app to render a chart to the view. the chart uses the model which is only accessible server side so I encode the model in JSON with inline js as shown below and then call the external function passing in the JSON string.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function () {
  
      var JSONdata = @Html.Raw(Json.Encode(Model.PastModels));
      var count = @Html.Raw(Json.Encode(Model.PastModels.Count));
      createChart(JSONdata, count);
  
  });
  </code></pre>
  
  <p></p>
  
  <p>The function is defined in an external file.</p>
  
  <pre><code>function createChart(JSONdata, count) {
      var dates = [];
      var scores = [];
      var name = ""
  
  
      for (i = 0; i &lt; count; i++) {
          dates[i] = JSONdata[i].TheDate;
          scores[i] = JSONdata[i].TotalScoreT;
      }
      var chart = 'totalChart';
      name = " Total Score";
      renderChart(chart, name);
  
  
      $('.nav-tabs a').click(function (e) {
          e.preventDefault();
          var tab = this.id;
  
          switch (tab) {
              case 'socialTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].SocialPhobiaT;
                  }
                  chart = socialChart;
                  name = ' Social Phobia';
                  break;
  
              case 'panicTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].PanicDisorderT;
                  }
                  chart = panicChart;
                  name = ' Panic Disorder';
                  break;
  
              case 'depressionTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].MajorDepressionT;
                  }
                  chart = depressionChart;
                  name = ' Major Depression';
                  break;
  
              case 'separationTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].SeparationAniextyT;
                  }
                  chart = separationChart;
                  name = ' Separation Anxiety';
                  break;
  
              case 'obsessiveTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].ObsessiveCompulsiveT;
                  }
                  chart = obsessiveChart;
                  name = ' Obsessive Compulsive Disorder';
                  break;
  
              case 'generalTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].GeneralizedAnxietyT;
                  }
                  chart = generalChart;
                  name = ' Generalized Anxiety';
                  break;
  
              case 'totalTab':
                  for (i = 0; i &lt; count; i++) {
                      dates[i] = JSONdata[i].TheDate;
                      scores[i] = JSONdata[i].TotalScoreT;
                  }
                  chart = totalChart;
                  name = ' Total Score';
                  break;
          }
  
          renderChart(chart, name);
      });
  }
  </code></pre>
  
  <p>I am including the external file using a section.</p>
  
  <pre><code>@section HeadValues{ 
      &lt;script src="https://code.highcharts.com/highcharts.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="https://code.highcharts.com/modules/exporting.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="~/scripts/RCADSResultPage.js" type="text/javascript"&gt;&lt;/script&gt; 
  
   }
  </code></pre>
  
  <p>However whenever the page is loaded I get the error 'function createChart is undefined'.</p>
  
  <p>Any suggestions would be much appreciated.</p>
  
  <p>Thanks.</p>