Using javascript code in MVC5 - where to put it

后端 未结 3 673
闹比i
闹比i 2020-12-09 18:21

Im having MVC5 application and in the view index.cshtml I need to use some java script code ,currently I put the script code inside the view and its working fine. My questi

3条回答
  •  醉梦人生
    2020-12-09 18:58

    You better use Razor @section for this.

    In your Layout:

    
         
              My Title
              .....
              @RenderSection("Scripts", false)
         
    
         
              @RenderBody
         
    
    

    In your View:

    Welcome!

    ...
    @section Scripts { }

    Some would prefer to place @RenderSection("Scripts") just before the tag instead.

提交回复
热议问题