Shanklen
Shanklen

Reputation: 11

Using ASP.NET Core MVC, how do I display an image?

I am trying to display an image for a gallery page I am creating. I'm very new to ASP.NET Core MVC. I saved the image in the same folder that my project is in.

This is what I have in my view file:

@{
    ViewData["Title"] = "Gallery";
}
<h2>Gallery Page</h2>
<img src="myImage.jpg" height="113" width="113" border="0" />

This is my gallery function in my controller:

public IActionResult Gallery()
{
    return View();
}

This is my output

Thank you for any help!

Upvotes: 1

Views: 2864

Answers (1)

Sathiya
Sathiya

Reputation: 239

In the img src you have directly gave the image name instead of create a new image folder and add the image file into that folder. change the html code as given below.

<img src="~/Folder Name/myImage.jpg" height="113" width="113" border="0" />

Upvotes: 2

Related Questions