This is my JavaScript function where I am able to pull data from action method in JSON format:
<script type="text/javascript">
$(document).ready(function () {
$.getJSON("/Home/GetUsers", null, function (data) {
var div = $('#ajaxDiv');
div.html("<br /> " + "Users received from server: " + "<br />");
$.each(data, function (i, item)
{
printUser(div, item);
});
});
});
function printUser(div, item)
{
div.append("<br/>" + "UserName: " + item.UserName + "<br/>" + "Id: " + item.Id);
<img src="@Url.Action("GetFileData", "Home", new { id = item.Id })" style="width:100px;height:100px;"/>
}
</script>
As you can see, I am able to get item.Id
, but how do I send it into src tag new { id = item.Id }
It is showing syntax error. I just want to show the image within this Ajax div. Please help me out.