title: How to get an ASP.NET Core MVC view to refer to a script section in another file?
body: <p>I'm facing an issue when I'm trying to link my <code>.cshtml</code> file and my JavaScript reference in an ASP.NET Core 6 MVC.</p>
  <p>As of right now, I have made a webpack setup such that it generates my JavaScript tags in a separate file called <code>home.sources.cshtml</code>:</p>
  <pre><code>@section Scripts
  {
      &lt;script src=&quot;/js/npm.popperjs.bundle.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;/js/npm.jquery.bundle.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;/js/npm.bootstrap.bundle.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;/js/home.bundle.js&quot;&gt;&lt;/script&gt;
  }
  </code></pre>
  <p>As you can see, my tags are encapsulated in the <code>Scripts</code> section. All these dependencies are for my <code>View/Home/Index.cshtml</code> page:</p>
  <pre><code>@{
      ViewData[&quot;Title&quot;] = &quot;Home Page&quot;;
  }
  
  &lt;div class=&quot;text-center&quot;&gt;
      &lt;h1 class=&quot;display-4&quot;&gt;Welcome&lt;/h1&gt;
      &lt;p class=&quot;test&quot;&gt;Learn about &lt;a href=&quot;https://docs.microsoft.com/aspnet/core&quot;&gt;building Web apps with ASP.NET Core&lt;/a&gt;.&lt;/p&gt;
  &lt;/div&gt;
  
  // Insert Script Section here
  </code></pre>
  <p>I want to make it so that the contents of <code>home.sources.cshtml</code> gets appended to this page at runtime. I don't want to manually add the script section myself, nor do I want to modify the page later on should I add more JavaScript dependencies. Any extra JavaScript dependencies that I add or remove will have their changes reflected only in <code>home.sources.cshtml</code>.</p>
  <p>How do I go about doing that?</p>
  <p>I was looking into <code>@Html.Partial()</code> in the attempt to add the <code>Script</code> section into the page as a partial view, but that doesn't seem to work.</p>