In the c#ASP MVC5, the JS file is arranged in an arbitrary folder and used in the cshtml file.

Asked 1 years ago, Updated 1 years ago, 49 views

Suppose you have the following folder configuration:

Any folder name 1
 <
 任意 Any folder name 2
  <
  任意 Any folder name 3
   <
   コント Controller name
    <
    InIndex.cshtml
    <
    In Index.js

By creating a RazorViewEngine in Application_Start on Global.asax.cs and registering the Index.cshtml location with the RazorViewEngine, we were able to view any location.
I would like to use Index.js from Index.cshtml in the above folder configuration example.
In Index.cshtml @section header

<script src="Index.js" type="text/javascript"></script>

I would like to know how to successfully deliver the external javascript file to the browser by describing
Thank you.

javascript c# asp.net

2022-09-30 16:32

1 Answers

I solved myself.Rename Index.js to IndexJS.cshtml.
IndexJS.cshtml uses a script tag to enclose the javascript code.
Write @Html.Partial ("IndexJS") in Index.cshtml.
Images like #include in c language
The external javascript file is now available in any folder.


2022-09-30 16:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.