在视图中显示图像,未找到文件

问题描述:

我希望在我的视图中显示图像。但文件没有找到,文件存在。在视图中显示图像,未找到文件

string file = Server.MapPath("~") + @"/App_Data/Plakaty/" + wyd.WydarzenieId.ToString() + ".jpg"; 
ViewBag.file_exist = System.IO.File.Exists(file); 

我尝试:(是只显示ALT :)

@if (ViewBag.file_exist == true) // it's TRUE 
     { 
      <img src="../../App_Data/Plakaty/1029.jpg" alt="p" /> 
      <img src="~/App_Data/Plakaty/1029.jpg" alt="p1" /> 
      <img src="@Url.Content("~/App_Data/Plakaty/1029.jpg")" alt="image"/> 
      <img src="@Url.Content("../../App_Data/Plakaty/1029.jpg")" alt="image2"/> 

     } 
+0

所以你说'ViewBag.file_exist'是真的? – 2013-04-22 10:53:05

+0

@vonv。对,是真的。 – user1031034 2013-04-22 10:55:31

<img src="../../App_Data/Plakaty/1029.jpg" alt="p" /> 

以此为例子,是真正的App_Data在图像与外界的道路?有时候内部路径是不同的。

+0

我将App_Data文件夹更改为另一个放置我的图像,它的工作。 – user1031034 2013-04-22 11:05:22

+0

请参阅http://*.com/questions/528858/what-is-the-app-data-folder-used-for-in-visual-studio – SPRBRN 2013-04-22 11:41:02