0

The src route is correct. Instead of the image, I get the default 'green hill blue sky' file image on my cshtml

<img src="../../wwwroot/images/images.jpg" width="30" height="30" alt="">

What I tried:

changing it from .jpg to .png

got the same results

Controller that loads the page:

basically, all it does is checks if a user is logged on or not by checking the session. Unsure if I should be doing anything else to also display the images. fairly new to this framework.

    [HttpGet]
    [Route("dashboard")]
    public IActionResult Dashboard()
    {
        if(HttpContext.Session.GetInt32("UserId") == null)
        {
            return RedirectToAction("Index","Home");
        }
        ViewBag.loggedinUser = HttpContext.Session.GetInt32("UserId");
        HttpContext.Session.SetInt32("DashboardTab", 0);
        return View("Dashboard");
    }
Md Farid Uddin Kiron
  • 16,817
  • 3
  • 17
  • 43
jgrewal
  • 342
  • 1
  • 10

2 Answers2

1

The issue is the link to your image. Try ~ instead of "wwwroot"

1

Firstly,check if you have app.UseStaticFiles(); in your Startup.cs.

Then try to use

<img src="~/images/images.jpg" width="30" height="30" alt="">

the tilde character ~/ points to the wwwroot.Refer to the official doc.

Yiyi You
  • 16,875
  • 1
  • 10
  • 22