Using the .NET MVC Controller Action as an HTML <img> Source
I am trying to display an image associated with a user in my database (image field data type image) on the page - unfortunately, the following code cannot do this.
HTML
<img src="/User/Picture/1" />
Controller action
public byte[] Picture(int id){
UserRepository r = new UserRepository();
return r.Single(id).logo.ToArray();
}
+3
2 answers
SOLVED PROBLEM
Sorry, I have not read enough about this!
All that had to be done was to make the Controller Action FileContentResult
public FileContentResult Picture(int id)
{
UserRepository r = new UserRepository();
return new FileContentResult(r.Single(id).logo.ToArray(), "image/jpeg");
}
+4