Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.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# 如果原始图像不可用,如何显示默认图像?_C#_Asp.net Mvc_Asp.net Mvc 3 - Fatal编程技术网

C# 如果原始图像不可用,如何显示默认图像?

C# 如果原始图像不可用,如何显示默认图像?,c#,asp.net-mvc,asp.net-mvc-3,C#,Asp.net Mvc,Asp.net Mvc 3,在我看来,我正在使用这段代码,我想显示设备图像,但在没有原始图像上传的情况下,我想显示一个默认图像(NoImage.jpg),但默认图像不显示 @if (item.EquipImage != null) { <td><img src="@Url.Content("~/Content/EquipImages/" + System.IO.Path.GetFileName(item.EquipImage))" alt="" width="70

在我看来,我正在使用这段代码,我想显示设备图像,但在没有原始图像上传的情况下,我想显示一个默认图像(NoImage.jpg),但默认图像不显示

  @if (item.EquipImage != null)
          {
         <td><img src="@Url.Content("~/Content/EquipImages/" + System.IO.Path.GetFileName(item.EquipImage))" alt="" width="70" height="70"/> </td>
          }else
          {
               <td><img src="@Server.MapPath("~/Content/EquipImages/NoImage.jpg")" alt="" width="70" height="70"/> </td>
          }
@if(item.EquipImage!=null)
{
}否则
{
}
===================================================================== 在Jsmith和Json的帮助下,代码正在运行。。我在这里粘贴工作代码,这可能对某些人有帮助:)

@if(!string.IsNullOrEmpty(item.EquipImage)){
}否则{
}

为什么对默认图像使用Server.MapPath而不是Url.Content?改为使用Url.Content,这样可以解决问题


如果不存在,则检查图像是否存在于指定的路径,但将路径粘贴到浏览器的url中,然后按enter键。或者使用Fiddler或浏览器开发工具来帮助您

为什么要对默认图像使用
Server.MapPath
,而不是
Url.Content
?改为使用
Url.Content
,这样可以解决问题。如果不存在,则检查图像是否存在于指定的路径,但将路径粘贴到浏览器的url中,然后按enter键。或者使用Fiddler或浏览器开发工具来帮助您。我还建议使用!string.IsNullOrEmpty(item.EquipImage)而不是item.EquipImage!=nullperfect,现在可以工作了。如何将你的评论标记为answer@Jason EvansI。我已经将我的文字粘贴到了答案中。
 @if(! string.IsNullOrEmpty(item.EquipImage)){

            <td><img src="@Url.Content("~/Content/EquipImages/" + System.IO.Path.GetFileName(item.EquipImage))" alt="" width="70" height="70"/> </td>
            }else{
               <td><img src="@Url.Content("~/Content/EquipImages/NoImage.jpg")" alt="" width="70" height="70"/> </td>
          }