好的,我有一些代码和sanapshot可以解释我的问题,

我有一个主页Main.Master,其中包含了cssjquery的所有引用,

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="CTVideos.Main" %>
<%@ Register Src="uc/LeftNav.ascx" TagName="LeftNav" TagPrefix="uc4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="UTF-8" />
    <title>Video</title>
    <meta name="viewport" content="initial-scale=1.0, width=device-width" />
    <!-- Style Sheets -->
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/bootstrap.min.css") %>" />
    <!-- Font Icons -->
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/font-awesome.min.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/ionicons.min.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/socicon-styles.css") %>" />
    <!-- Font Icons -->
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/hover-min.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/owl.carousel.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/animate.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/css-menu.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/loader.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/styles.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/responsive.css") %>" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body id="index-v2">
    <form id="form1" runat="server">
        <uc1:LeftNav runat="server" ID="LeftNav" />
        <asp:ContentPlaceHolder ID="cpl_chlid" runat="server">
        </asp:ContentPlaceHolder>
    </form>
    <!-- Scripts -->
    <script src="<%#ResolveUrl("~/js/wow.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/jquery-1.12.3.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/bootstrap.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/owl.carousel.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/css-menu.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/jquery.validate.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/custom.js")%>"></script>
</body>
</html>


并在Main.Master页面加载事件中

public partial class Main : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.DataBind();
    }
}


我项目的根目录就是这样

jquery - ResolveUrl在asp.net的母版页中不起作用-LMLPHP

View文件夹内的WebForm1WebForm2和其他WebForms是从Main.Master页继承的。 WebForm1WebForm2可以按预期加载,但是View文件夹内的所有WebForms均未正确加载,从而干扰了设计

最佳答案

从所有css文件中删除ResolveUrl并附加它们简单的原因,因为只有脚本才需要ResolveUrl。只需从css文件中删除ResolveUrl,它将可以正常工作。

解决方案2-

您可以在ResolveUrl中将#符号替换为=



<%# ResolveUrl("~/js/wow.min.js") %>

<%= ResolveUrl("~/js/wow.min.js") %>

解决方案2对我有用。

关于jquery - ResolveUrl在asp.net的母版页中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42172986/

10-11 08:24