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

Posted by Jimbo on Stack Overflow See other posts from Stack Overflow or by Jimbo
Published on 2010-06-15T14:10:03Z Indexed on 2010/06/15 14:12 UTC
Read the original article Hit count: 164

I'm trying to display the picture associated with a user in my database (the picture field's data type is image) on a page - unfortunately the code below fails to do that.

HTML

<img src="/User/Picture/1" />

Controller Action

public byte[] Picture(int id){
    UserRepository r = new UserRepository();
    return r.Single(id).logo.ToArray();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc