How to Properly Reference a JavaScript File in an ASP.NET Project?

前端 未结 4 944
醉梦人生
醉梦人生 2021-01-02 22:27

I have some pages that reference javascript files.

The application exists locally in a Virtual Directory, i.e. http://localhost/MyVirtualDirectory/MyPage.aspx

<
4条回答
  •  时光取名叫无心
    2021-01-02 22:31

    Another way in MVC5:

    1) in the layout html View file, place RenderSection in the place you need the script to be:

    
    @RenderSection("scripts1", required: false)
    
    

    note that you can change the "Scripts1" to be whatever name you like.

    2) in your view html file, just call the "scripts1", doesn't matter where, with your path and js file name:

    @Scripts1.Render("~/Scripts/MyScript.js")
    

    3) make sure the MyScript js file is in the Scripts Folder of your project.

    That's it.

提交回复
热议问题