Reputation: 175
I try to detect if <img>
src
not found change it with another src
using JQUERY, I work on ASP.NET MVC project, and the src
come from Controller.
This is what I try :
HTML
@foreach (var item in ViewBag.DATA)
{
if (item.IMG_FRMTR != null)
{
ViewBag.IMG = String.Format("data:image/jpg;base64," + Convert.ToBase64String(item.IMG_FRMTR));
}
}
<img id="IMG" src="@ViewBag.IMG" onerror="standby()" style="width:200px;height:200px">
JQUERY
function standby() {
document.getElementById('IMG').src = 'https://www.google.com/images/srpr/logo11w.png';
}
Controller Action
ViewBag.DATA = PROF_model.Select(CIN);
return View();
PROF_model.Select Method
public static List<FRMTR> Select(string CIN)
{
var R = (from P in SCHOOL_DB_Context.Con.FRMTRs where P.CIN_FRMTR == CIN select P).ToList();
return R;
}
Please any help ?
Note : I look for a lot solution here in Stackoverflow but no one solve my problem
Thanks in advance <3
Upvotes: 0
Views: 89