我知道你不能把控件放在像这样的C#函数中
<%= VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />) %>
但我想知道你是否可以将值从控件传递给C#函数 umbraco:上面的项目输出类似〜/ media / bg1.jpg
的内容以下是我要做的事情:
<%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="cphHead" runat="server">
<style type="text/css">
#content {
background: url('<%=VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />)%>');
}
</style>
</asp:content>
任何人都知道任何解决方案?提前谢谢。
答案 0 :(得分:3)
如果它只是一个简单的文本字符串,那么您可以执行以下操作:
<%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<%@ Import Namespace="umbraco" %>
<%@ Import Namespace="umbraco.presentation" %>
<%@ Import Namespace="umbraco.presentation.nodeFactory" %>
<asp:content ContentPlaceHolderId="cphHead" runat="server">
<style type="text/css">
#content {
background: url('<%=VirtualPathUtility.ToAbsolute(Node.GetCurrent().GetProperty("background").Value)%>');
}
</style>
</asp:content>
但是,如果“background”属性是媒体选择器,那么您需要更多的帮助而不仅仅是那个,这将涉及umbraco.cms.businesslogic.media命名空间。我建议您使用Reflector或Codeplex上的源代码存储库检查库,以找出您应该使用的类以及如何随后填充您的属性。
HTH,
本杰明