Include JavaScript file in partial views

后端 未结 9 1527
别跟我提以往
别跟我提以往 2020-12-02 06:13

I am wondering what the best practice is for including javascript files inside partial views. Once rendered this will end up as a js include tag in the middle of my page\'s

9条回答
  •  一个人的身影
    2020-12-02 06:52

    The designers of MVC went through a lot of trouble to prevent us from using code-behinds, but by creating a file named .aspx.cs and modify the inherits attribute of the aspx page accordingly, it is still possible to get them.

    I'd say, the best place to put the include would be in the Page_Load handler in the codebehind (using Page.ClientScript.RegisterClientScriptInclude).

提交回复
热议问题