I created a service to get member information using entity framework.
then i used the service like this.
[HttpGet]
public JsonResult GetMemberImageData(string MemberId)
{
try
{
var memberPhoto = memberService.GetById(Convert.ToInt32(MemberId));
MemberViewModel myMember = new MemberViewModel();
myMember.MemberCode = Convert.ToBase64String( memberPhoto.MemberImg );
List<MemberViewModel> List_ViewModel = new List<MemberViewModel>();
List_ViewModel.Add(myMember);
return Json(List_ViewModel.ToList(), JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{ return Json(ex.ToString(), JsonRequestBehavior.AllowGet); }
}
in view: .cshtml file::
function GetMemberPhotoSignature(member)
{
//alert(member);
$.ajax({
type: 'GET',
contentType: "application/json; charset=utf-8",
url: '@Url.Action("GetMemberImageData", "SpecialSavingCollection", "http")',
data: { MemberId: member },
dataType: 'json',
async: true,
success: function (data) {
$('#AjaxLoader').hide();
$.each(data, function (index, data) {
if (data != "Error") {
alert(data.MemberCode);
$("#target").attr("src", "data:image/gif;base64, " + data.MemberCode);
//$("#EmployeeID").val(data.EmployeeID);
}
else {
// $("#EmployeeName").val('');
}
});
},
error: function (request, status, error) {
$('#AjaxLoader').hide();
// $.alert.open("Employee Does Not Exist");
}
});
HTML::
<img id="target" src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />