gpt4 book ai didi

ASP.NET内联编码: variable name is not replaced with value

转载 作者:行者123 更新时间:2023-12-02 10:18:36 24 4
gpt4 key购买 nike

我有一个 ASP.NET 页面。在页面加载中,我设置了公共(public)变量的值。在内联编码部分中,我正在加载一个 CSS,它是具有公共(public)变量中可用名称的文件夹.我的HTML标记如下

<%@ Page Language="C#"  EnableEventValidation="false" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"  Theme="GridView" Inherits="GUI.MyPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MyPage</title>
<link href="../Vendors/<%=vendorName%>/css/style.css" rel="stylesheet" type="text/css" />

</head>
<body>
<%=vendorName %> <!-- here value is printed correctly -->
...
</body>

在我的代码后面

 public partial class MyPage: MyCommonClass
{
public string vendorName = "";
protected void Page_Load(object sender, EventArgs e)
{
vendorName = "ACLL";
}

}

但是当我运行页面时, <%=VEndorId%> 不会被其中的值替换。但是在正文中,它打印正确。但在头部它没有出现。我检查了 ViewSource 并找到源码HTML如下

<link href="../Vendors/&lt;%=vendorName%>/Lib/css/tradein.css" rel="stylesheet" type="text/css" />

最佳答案

这两个选项是:

<link href="<%= string.Format("../Vendors/{0}/css/style.css", vendorName) %>" type="text/css" rel="Stylesheet" /> // as Greco stated

<style>
@import url("../Vendors/<%=vendorName%>/css/style.css");
</style>

关于ASP.NET内联编码: variable name is not replaced with value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1198475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com