Visual Studio Code how to display an image in .CSHTML web page in Windows?

BillNew 36 Reputation points
2023-04-24T18:15:27.6933333+00:00

Created several Visual Studio Test projects and yet to figure out how to display an image on the web page. Using something like this in the .CSHTML Page: <img src="localimage.jpg"> The image shows up as a box indicating that the image was not found on the web page when running the Visual Studio Code application. Have tried pointing directly to the file on the local hard drive... Same result. Eventually will work the code into an actual web page and need the images to display properly using a Web Browser... Using Firefox at the present time. Any hints on how to resolve this issue? Thank you!

Developer technologies ASP.NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2023-04-25T02:46:54.1833333+00:00

    Hi @BillNew,

    According to your previous post, your project should be Asp.net MVC.

    First copy the image in your project root folder and then try the code below.

    <img src="@Url.Content("~/localimage.jpg")" alt="IMAGES" />

    Best regards,

    Lan Huang


    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.