相关疑难解决方法(0)

使用ASP.NET MVC在详细信息页面模板中显示数据库中的byte []数组图像

当我尝试使用以下内容在Details页面模板中显示byte []数组图像时:

public FileContentResult RenderPhoto(byte[] photo)
{
    // var array = (byte[])Session["photo"];
    // return File(array, "image/jpeg");

    return File(photo, "image/jpeg");
}

<img src="@Url.Action("RenderPhoto", Model.Photo)"/>
Run Code Online (Sandbox Code Playgroud)

照片为空.

如果我在会话中存储student.Photo:

//
// GET: /Student/Details/5

public ViewResult Details(int id)
{
    Student student = db.Students.Find(id);

    Session["photo"] = student.Photo;

    return View(student);
}
Run Code Online (Sandbox Code Playgroud)

并尝试显示从Session(上面的注释行)中检索值的图像.

为什么我在第一种情况下获得空值?

将学生传递给View in后ViewResult Details(int id),Model.Photo不再保留该值了吗?

database asp.net-mvc image url-action

3
推荐指数
1
解决办法
7239
查看次数

标签 统计

asp.net-mvc ×1

database ×1

image ×1

url-action ×1