图像控制不起作用
我有以下 ASP 代码:
<asp:DataList ID="dlGallery" runat="server"
<ItemTemplate>
<div style="float: left; padding-right: 10px; text-align: center">
<img src="<%= ApplicationPath%><%# Eval("ImageUrl") %>"width="80"/>
</ItemTemplate>
</asp:DataList>
我收到此错误: 编译器错误消息:CS0103:当前上下文中不存在名称“ApplicationPath”
这是什么意思?ApplicationPath 可能存在什么问题?
先感谢您
I have the Following ASP code:
<asp:DataList ID="dlGallery" runat="server"
<ItemTemplate>
<div style="float: left; padding-right: 10px; text-align: center">
<img src="<%= ApplicationPath%><%# Eval("ImageUrl") %>"width="80"/>
</ItemTemplate>
</asp:DataList>
I get this Error:
Compiler Error Message: CS0103: The name 'ApplicationPath' does not exist in the current context
What is it mean?What may be problem with ApplicationPath?
Thank You in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我学会的第一个 .NET 技巧之一是简单地在前面添加 <%= Request.ApplicationPath %>到页面中任何路径的开头,例如:
/Images/Foo.gif' ... />
问题是,当请求文件时,它会返回“相对于根目录”,而没有尾部斜杠。这意味着当从网站的根文件夹请求页面时,Request.ApplicationPath 返回“/”。在上面的示例中,将写出以下字符串:
在针对 localhost 进行开发时不会出现这种情况,因为应用程序将位于网站根目录下的一级,这意味着虚拟目录名称将在斜杠“/”之后返回:
但是,如果从子文件夹中的页面请求页面,则路径将返回为“/FldrName”,并且上面的示例将正确解析为:
'从根目录
' 在虚拟目录中
One of the first .NET tricks I learnt to simply prepend <%= Request.ApplicationPath %> to the beginning of any paths in your pages, such as:
/Images/Foo.gif' ... />
The problem is that, when a file is requested, it is returned "root-relative" without a trailing slash. This means that when a page is requested from the root folder of a Website, Request.ApplicationPath returns '/'. In the above example the following string will be written out:
This wouldn't be picked up when developing against localhost because the application will be one level under the root of the Website meaning that the virtual directory name will be returned after the slash '/':
However, if a page is requested from a page in a sub-folder, then the path is returned as "/FldrName" and the above example will resolve correctly as:
' From the root
' In a virtual directory
尝试导入到存在 ApplicationPath 的 aspx 文件命名空间。
或指定具有完整命名空间的变量
src="<%= YourNamespace.ApplicationPath%>
Try to import to aspx file namespace where ApllicationPath exists.
or specify variable with full namespace
src="<%= YourNamespace.ApplicationPath%>