ImageUrl在项目文件夹中找不到图像

时间:2018-09-11 06:07:26

标签: c# html5 webforms

我想创建一个网站,该网站将在“主页”页面中存储2张图片,这将导致2个不同的页面。在这种情况下,我正在使用工具箱中的Image对象。当我尝试分配ImageUrl时,无论格式如何,它似乎都找不到任何东西。我尝试了多张照片,使用了不同的文件夹,结果如下:

enter image description here

我也试图用C#编程地更改它,但也无法正常工作:

$("#txtToDate").change(function () {
    var start = new Date(getDate($('#txtFromDate').val()));
    var end = new Date(getDate($('#txtToDate').val()));

    diff = new Date(end - start),
        days = diff / 1000 / 60 / 60 / 24;
    if (days == NaN) {
        $('#txtTotalDays').val(0);
    } else {
        $('#txtTotalDays').val(days);
    }
})

我应该使用通常的Image1.ImageUrl = @"Images/left.jpg"; 查找图像吗?非常感谢你!

3 个答案:

答案 0 :(得分:0)

如果您确定您的路径值包含ImageFiles目录中的相应路径,那么您应该能够使用以下内容:

<asp:Image ID="Image1" runat="server" ImageUrl='~/ImageFiles/<%# Eval("path")%>' />

或使用Eval方法的集成字符串格式,如下所示:

<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("path", "~/ImageFiles/{0}") %>' />

答案 1 :(得分:0)

右键单击显示的图像,然后选择“包括在项目中”,然后尝试提供imageUrl

答案 2 :(得分:0)

在后面的代码中,您可以执行以下操作,包括在应用程序基本URL中执行以下操作-

  

Image1.ImageUrl = @“〜/ Images / left.jpg”

请参考以下讨论以获取更多信息-

Image isn't showing in Image and ImageButton

  

ASP.NET将自动将〜替换为您的应用程序的基础   URL,因为Image1是服务器控件