zero_coding zero_coding - 7 months ago 37
ASP.NET (C#) Question

Append javascript file into view

I created an application that based on ASP.NET Core .NET Framework.

I have a view and want to add javascript file on it and did as follow:

ViewData["Title"] = "Index";

<script src=""></script>
<script src="~/js/app.js"></script>
<input id="greet" value="Hello!" type="button"/>

I do not add to the layout template, because it is only for view specific.

The file structure looks as follow:

enter image description here

My problem is, when I start the application, then the javascript file
does not load at all, also
What am I doing wrong?

Kld Kld


In your view

@section scripts {
       <script src="~/js/app.js"></script>

In your layout

@RenderSection("scripts", required: false)


in your view:

@section Styles {
    <link href="~/Content/contact.css" rel="stylesheet" type="text/css" />

In your layour

@RenderSection("styles", false)