【问题标题】:What is the difference between Image Attribute and ImageURL in ASP.NET?ASP.NET 中的 Image Attribute 和 ImageURL 有什么区别?
【发布时间】:2013-10-06 14:27:29
【问题描述】:

我已经用谷歌搜索并抓取了关于此的信息,但找不到任何可靠的信息。

在 ASP.NET 中更改图像的照片来源有什么区别

myImage.Attributes["src"] = "/files/image1.jpg";

myImage.ImageUrl = "~/files/image1.jpg";

【问题讨论】:

  • 当你尝试它会发生什么?

标签: asp.net webforms


【解决方案1】:

ImageUrl 属性的优点是您可以使用 ~ 字符,它代表应用程序根。

myImage.ImageUrl = "~/files/image1.jpg";

这在应用程序的根目录位于子文件夹中并且您不需要在代码中硬编码文件夹名称的情况下很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-23
    • 2011-01-06
    • 2013-12-29
    • 1970-01-01
    • 2016-02-20
    • 2020-03-23
    • 2021-08-04
    • 1970-01-01
    相关资源
    最近更新 更多