Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net Visual Studio中以web窗体显示图像?_C#_Asp.net_Image_Visual Studio - Fatal编程技术网

C# 如何在asp.net Visual Studio中以web窗体显示图像?

C# 如何在asp.net Visual Studio中以web窗体显示图像?,c#,asp.net,image,visual-studio,C#,Asp.net,Image,Visual Studio,我已在根项目文件夹中创建了一个图像文件夹 <asp:Image ID="Image1" runat="server" ImageUrl="~/images/" /> 当我访问网页时,我得到一个带有x的小img框,而不是我的图像。 <asp:Image ID="Image1" runat="server" ImageUrl="~/images/" /> 正在将url设置为目录(文件夹),而不是图像。这就是为什么你得到的是一个小图像框,而不是一个图像 如果要在页面加载时

我已在根项目文件夹中创建了一个图像文件夹

<asp:Image ID="Image1" runat="server" ImageUrl="~/images/" />
当我访问网页时,我得到一个带有x的小img框,而不是我的图像。


<asp:Image ID="Image1" runat="server" ImageUrl="~/images/" />
正在将url设置为目录(文件夹),而不是图像。这就是为什么你得到的是一个小图像框,而不是一个图像

如果要在页面加载时显示图像,请将其设置为有效图像:

<asp:Image ID="Image1" runat="server" ImageUrl="~/images/picture1.jpg" />

尝试使用.Scr而不是ImageUrl

<asp:Image ID="Image1" runat="server" ImageUrl="~/images/" /> 

希望这有帮助

它正在显示带有X的小图像框,因为它无法在指定的路径上找到图像

因此,将图像文件夹添加到wwwroot文件夹中,而不是项目根目录中


之后,您可以使用
answer

@dwillight右键单击该x图像,然后单击“在新选项卡中打开图像”,查看url是否有效?此外,代码行无效Image1.ImageUrl=“~/images/picture1。它缺少图像扩展名和结束引号。@MohsinMehmood这只是一个输入错误。我在实际代码中有扩展名和引号。它不允许我选择“在新选项卡中打开链接”“选项它将灰显。我正在Internet Explorer上运行此操作。请尝试其他浏览器,例如chrome。另外,设置ImageUrl的代码是基于下拉选择值的有条件代码,因此请确保此代码正在执行。@MohsinMehmood好的,我在Chrome中尝试了此代码,并在“新建”选项卡中选择了“打开图像”,收到一条错误消息,指出“403.14 Web服务器配置为不列出此目录的内容。”另外,我不确定你所说的ImageUrl是基于条件的。我将如何更改它?这意味着如果(dropDownList.SelectedItem.Value==“Picture 1”)不起作用,并且ImageUrl设置为“~/images/”而不是“~/images/picture1.jpg”服务器端映像的ImageUrl设置为
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/" /> 
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/picture1.jpg" /> 
 <asp:DropDownList 
             ID="DropDownList1"
             runat="server"
             AutoPostBack="true"
             OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
 protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        Image1.ImageUrl = "~/images/" + DropDownList1.SelectedItem.Value;
    }