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
standbyfunction ever invoked? What specifically happens? The intended functionality appears to work as expected in isolation: jsfiddle.net/uhn7zLmwstandbyfunction not executedonerrorevent isn't triggered then it sounds like there's no error. For the<img>element which should be triggering an error, what is the actual resulting client-side element in the browser? Whatsrcvalue is there? In the browser's debugging tools, in the network tab, what is the request made for thatsrcand what is the server's response?src="@(string.IsNullOrWhitespace(ViewBag.IMG) ? "~/0.jpj" : ViewBag.IMG)"where0.jpgdoesn't exist