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 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shubham KumarPosted Feb 18, 2016, 5:27 AM
wassim safaPosted Feb 18, 2016, 3:51 AM
Amit Kumar SinghPosted Feb 18, 2016, 3:36 AM