【问题标题】:how doI display image from images file within my wwwroot on my cshtml如何在我的 cshtml 上的 wwwroot 中显示图像文件中的图像
【发布时间】:2021-09-22 23:44:14
【问题描述】:

src 路由是正确的。而不是图像,我在我的 cshtml 上获得了默认的“青山蓝天”文件图像

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

我尝试了什么:

将其从 .jpg 更改为 .png

得到相同的结果

加载页面的控制器:

基本上,它所做的只是通过检查会话来检查用户是否登录。不确定我是否应该做其他事情来显示图像。这个框架相当新。

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

【问题讨论】:

    标签: asp.net-mvc image asp.net-core razor wwwroot


    【解决方案1】:

    问题在于您的图片的链接。 尝试~ 而不是“wwwroot”

    【讨论】:

      【解决方案2】:

      首先,检查您的 Startup.cs 中是否有 app.UseStaticFiles();

      那就试试用

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

      波浪字符~/指向wwwroot。参考官方doc

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        • 2012-10-14
        • 2017-03-20
        • 2020-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多