hi,plz i need help for loading image saved at sql server from MVC 5.
i used to call $.ajax({ url: './cName '/OpenDocument/?id=' + dataRecord.DocumentID_PK, data: '', type: 'POST' });
and at controller:
public byte[] GetImageFromDataBase(int Id)
{
var q = from temp in db.VwDocuments where temp.DocumentID_PK == Id select temp.DocumentContent;
byte[] cover = q.First();
return cover;
}
public FileResult OpenDocument(int id)
{
try
{
byte[] cover = GetImageFromDataBase(id);
if (cover != null)
{
//return File(cover, "image/jpg");
return File(cover,"application/octetstream", "elementary19240001");
}
else
{
return null;
}
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 17, 2016, 10:36 PM EST
wassim safa4 reputationPosted Feb 17, 2016, 10:51 PM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 18, 2016, 12:27 AM EST