javascript - Load image in ajax query (ASP.NET) -
i make ajax call , return json end
here code of ajax call
<script> $('#search').click(function () { $("#patients").empty(); var lname = $("#lname").val(); var model = { lastname: lname }; $.ajax({ url: '@url.action("resultofsearch", "patientdatabase")', contenttype: 'application/json; charset=utf-8', data: json.stringify(model), type: 'post', datatype: 'json', processdata: false, success: function(data) { var list = data; //alert(list); var listnumber = 1; (var = 0; <= list.length - 1; i++) { var arrow = '@url.content("~/images/doc-50.png")'; var patientslist = ' <td class="point">' + (i+1) + '</td>' + '<td class="title"> ' + list[i].dateofbirthday + '</td>' + '<td class="title"> ' + list[i].firstname + '</td>' + '<td>' + '</td>' + '<td>' + '</td>' + '<td>' + '</td>' + '<td style="text-align:end;>' + arrow + '</td>'; $("#patients").append('<tr>' + patientslist + '</tr>'); }; } }); });
in row try show image
+ '<td style="text-align:end;>' + arrow + '</td>';
image in arrow value var arrow = '@url.content("~/images/doc-50.png")';
but not showing. have no errors in console related image.
what wrong in code?
you have use image tag inside td
, use arrow
src
attribute of image because @url.content
used when wish resolve url file or resource on site , pass relative path, returns application absolute path file.
like below
'<td style="text-align:end;"><img src=' + arrow + '/></td>';
btw version of .net mvc using? mvc 4 , above can directly use relative url in image src="~/images/doc-50.png"
Comments
Post a Comment