Using a .NET MVC Controller Action as the Source for an HTML <img>

余生长醉 提交于 2019-12-04 14:28:43
Jimbo

PROBLEM SOLVED

Apologies, I didn't read up enough on this!

All that needed to be done was make the Controller Action return FileContentResult

public FileContentResult Picture(int id)
{
    UserRepository r = new UserRepository();   
    return new FileContentResult(r.Single(id).logo.ToArray(), "image/jpeg");
}
queen3

This question has a lot of useful answers. You probably need the FileContentResult-related answers.

In short, you need to return appropriate ActionResult, and not just array of bytes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!