How to show image in Razor component

李畋岷 76 Reputation points
2022-02-07T08:09:10.027+00:00

I write a Razor component in an asp.net core project as below:

<div>
<table class="layui-table">
<tbody id="PTb" style="display: block;height: 600px;width:1000px;overflow: auto">
<tr style="display:block">
<td style="vertical-align:top"><img src="2271.jpg" /></td>
</tr>
</tbody>
</table>
</div>

@Aidan Wick {
//private ElementReference title;
}

The image "2271.jpg" can not be displayed no matter which render-mode is used. The picture "2271.jpg" is placed under the same folder as the razor file. How should this picture be displayed?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,203 questions
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,021 Reputation points Microsoft Vendor
    2022-02-08T01:44:01.983+00:00

    Hi @李畋岷 ,

    In Asp.net core application, by default the static files (such as HTML, CSS, images, and JavaScript) are stored within the project's web root directory. More detail information, see Static files in ASP.NET Core.

    So, you could try to create an images folder in the wwwroot folder, and put the image into the images folder. Then, you can display the image like this:

    <img src="images/Image1.png" />  
    

    The result is like this:

    172000-image.png


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. 李畋岷 76 Reputation points
    2022-02-08T07:58:54.127+00:00

    172126-image.png

    OK. But excuse me to ask last question. What does the above mean?