wassim safa

wassim safa

  • NA
  • 4
  • 2.2k

load image from sql server using mvc 5

Feb 18 2016 3:04 AM
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;
}
 

Answers (3)