asp.net-mvcimageasp.net-corerazorwwwroot

how doI display image from images file within my wwwroot on my cshtml


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");
    }

Solution

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