title: Can I use Razor syntax inside Javascript included in a ScriptBundle?
body: <p>I have a control that features code similar to the following:</p>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>$("#Postcode").autocomplete({
      source: '@(Url.Action("AutocompleteHelper"))'
  });
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <p><code>@Html.EditorFor(model =&gt; model.Postcode)</code></p>
  
  <p><br>It used to all sit directly inside a .cshtml file and <code>Url.Action</code> generated a working URL as expected.</p>
  
  <p>Recently I needed to use this in a number of views, so I moved the JS into a separate .js file (wrapped into a <code>ScriptBundle</code> and included in the parent view via <code>@Scripts.Render</code>) and the corresponding HTML is now rendered as a partial view.</p>
  
  <p>A side-effect of this is that the Razor transformation no longer occurs. I'd prefer not to replace <code>Url.Action</code> with a hardcoded <em>/&lt;Controller&gt;/AutocompleteHelper</em> string, so is there any other way I can dynamically generate and set this value? I could move the Javascript out of the bundle and into the partial view, but the consensus seems to be that you shouldn't have JS in a partial view.</p>