p.deman
p.deman

Reputation: 602

Display image razor pages

I am trying to display images on my web api that are located on the server side. for now I have added them in my solution in visual studio (I added two to try, I specified one as embedded ressource and one as none as build action. they are directly in WebAPISolution/xxx.png not in a subfolder

In my cshtml page, I put this:

<div>
<p>Test image</p>
     <img id="img1" alt="Image1.png" src="@Url.Content("~/Image1.png")">
</div>

and on my web page it doesn't shows up. it seems to look for it at:

view-source:https://xx.xx.xx.xx:5001/Image1.png

and the error message is

"can't be displayed because it contains error"

, it just doesn't find it I guess because the same with ImageXXX.png which doesn't exist return the same error I don't get why the image doesn't shows up.

here is how is organized my solution folder enter image description here

Upvotes: 3

Views: 17336

Answers (1)

Alaaeddine HFIDHI
Alaaeddine HFIDHI

Reputation: 886

1 ) In your Startup Class you should add app.UseStaticFiles(); within public void Configure() method
2) Put your image in the wwwroot folder
3) add this code to your razor view <img src="~/Image1.png" />

Upvotes: 3

Related Questions