I got controller which returns list of pathes with images in Json. I want to parse it and output images one by one. But my ajax script not working.
(also I added @Html.ActionLink which is working ok when I click on the link).
So heres the code
Script:
<div>
@Html.ActionLink("Header", "GetImagesList") ;
<script type="text/javascript">
$.ajax({
url: "/Header/GetImagesList",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (text) {
var fileList = JSON.parse(text);
for (var i = 0; i < fileList.length; i++) {
document.write("<div>" + " <img src="+fileList[i]+" alt=\"image\" /> "+ "</div>");
}
alert("test");
}
});
</script>
</div>
Controller
public ActionResult GetImagesList()
{
var imagesList = Directory.GetFiles("C:\\Images");
return Json(imagesList, JsonRequestBehavior.AllowGet);
}