0
我的問題是這樣的:我想從它的diretory中選擇圖像,與它們的數量無關,並通過ul/li將其列在div中。我有這樣的代碼中的HomeController:如何在div中列出圖像
public ActionResult ContactUs()
{
return View();
}
public ActionResult ListImagesProducts()
{
DirectoryInfo diretorio = new DirectoryInfo(@"~\Content\images\Products\");
FileInfo[] Arquivos = diretorio.GetFiles("*.*");
List<string> model = new List<string>();
foreach (FileInfo fileinfo in Arquivos)
{
model.Add(fileinfo.Name);
}
var diretory = model;
return Json(diretory, JsonRequestBehavior.AllowGet);
}
而在聯繫我們的看法,我有這樣的代碼:
@{
ViewBag.Title = "Three Jay - Produtos";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(getImages);
function getImages() {
$.getJSON("Home/ListImagesProducts", showImages);
}
function showImages(data) {
for (i = 0; i < data.length; i++) {
var images = data[i];
$("#diretoryImages").append("<li>" + images.toString + "</li>");
}
}
</script>
<div id = "diretoryImages" />
我在做什麼錯?你們可以幫我嗎?
哦,謝謝。但實際上,我的代碼並未向我顯示目錄名稱,就像代碼中的問號一樣。 –