Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image display on MVC view

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

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.

On execution, the page is not displaying the images. Let us know if anything wrong here?

like image 695
Jyothi Srinivasa Avatar asked Mar 09 '11 15:03

Jyothi Srinivasa


People also ask

What is display mode in MVC?

Display modes in ASP.NET MVC 5 provide a way of separating page content from the way it is rendered on various devices, like web, mobile, iPhone, iPod and Windows Phones. All you need to do is to define a display mode for each device, or class of devices.


1 Answers

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:

<img src= "@Url.Content(Model.PictureLocation)" alt="IMAGES" /> 
like image 135
Darin Dimitrov Avatar answered Nov 10 '22 07:11

Darin Dimitrov