asp.net-mvc MVC 视图上的图像显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5248273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image display on MVC view
提问by Jyothi Srinivasa
I am trying to display image on the cshtml file. The spam filter prevents me from typing the HTML for image. However the source is set to
我正在尝试在 cshtml 文件上显示图像。垃圾邮件过滤器阻止我为图像输入 HTML。但是源设置为
src= "@Html.Encode(Model.PictureLocation)" alt="IMAGES"
In viewsource it shows as
在视图源中它显示为
src= "C:\Documents and Settings\xxx\My Documents\Visual Studio 2010\Projects\MVC\TIQC_ServerInterface\TIQC_ServerInterface\uploads\FileUpload12011_03_02_11_49_22.jpg" alt="IMAGES"
The image is present in the location mentioned in the src path.
该图像存在于 src 路径中提到的位置。
On execution, the page is not displaying the images. Let us know if anything wrong here?
执行时,页面不显示图像。让我们知道这里是否有任何问题?
回答by Darin Dimitrov
You have specified an absolute path which doesn't exist on the client computer. Try like this:
您指定的绝对路径在客户端计算机上不存在。像这样尝试:
<img src= "@Url.Content("~/uploads/FileUpload12011_03_02_11_49_22.jpg")" alt="IMAGES" />
or if your model variable contains "~/uploads/FileUpload12011_03_02_11_49_22.jpg" you could:
或者如果您的模型变量包含“~/uploads/FileUpload12011_03_02_11_49_22.jpg”,您可以:
<img src= "@Url.Content(Model.PictureLocation)" alt="IMAGES" />
回答by davehauser
The path in the src
attribute must be relative to the website root, not the absolute path on the server. So in your case that would probably be something like "/uploads/FileUpload12011_03_02_11_49_22.jpg"...
src
属性中的路径必须相对于网站根目录,而不是服务器上的绝对路径。因此,在您的情况下,这可能类似于“/uploads/FileUpload12011_03_02_11_49_22.jpg”...