CrazyC
CrazyC

Reputation: 1896

Image Reference issue in MVC

I am creating a line chart in one view(myChartView) and saving it as _ChartFiles/chart01.jpg. var filePathName = "_ChartFiles/chart01.jpg";

Which is saving at /views/myChartView/_ChartFiles/chart01.jpg . Now in the very next line making a reference it as

<img src="@filePathName" />

but this is not displaying the image. what would be correct way to refer it?

Upvotes: 0

Views: 51

Answers (4)

vicky
vicky

Reputation: 1580

//try this one
filePathName = "myChartView/_ChartFiles/chart01.jpg";
<img src="@filePathName" />

Upvotes: 0

Nivya M
Nivya M

Reputation: 102

Try giving the image path as

filePathName = "../views/myChartView/_ChartFiles/chart01.jpg";

or

filePathName = "~/views/myChartView/_ChartFiles/chart01.jpg";

Upvotes: 0

Charlie
Charlie

Reputation: 177

You should save it in another folder than "Views" because in MVC this is a folder conventionned for HTML view and no other content, try to save it in "fonts" or whatever else, and it would be :

<img src="fonts/yourimage.jpg" />

Upvotes: 0

haim770
haim770

Reputation: 49095

If you want some static files to be accessed directly by the client, you cannot store them in the ~/Views folder because by default (for security reasons) the server would not serve content from this folder.

See ~/Views/Web.Config:

<handlers>
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>

Try to save the files in other directory like ~/Static.

Upvotes: 1

Related Questions