Using scripts in a master page with ASP.NET MVC

前端 未结 11 1336
难免孤独
难免孤独 2020-11-28 19:06

I\'m fairly new to ASP.NET MVC, and I\'m having a little trouble with scripts... in particular, I want to use jQuery in most pages, so it makes sense to put it in the master

11条回答
  •  不知归路
    2020-11-28 19:30

    At work we are doing something like this from the ASP code behind:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      Const jQuery As String = "jQuery"
    
      With Me.Page.ClientScript
        If Not .IsClientScriptIncludeRegistered(jQuery) Then
          .RegisterClientScriptInclude(jQuery, VirtualPathUtility.ToAbsolute("~/Includes/jQuery-1.2.6.js"))
        End If
      End With
    End Sub
    

    I don't know if it's possible to do that with ASP.NET MVC.

提交回复
热议问题