我的问题是这样的:我想从它的指示中选择图像,与它们的数量无关,并通过ul / li将它列在div中。我在HomeController中有这段代码:
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);
}
在ContactUs视图中,我有以下代码:
@{
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" />
我做错了什么?你们可以帮帮我吗?
答案 0 :(得分:0)
不知道您的实际问题是什么,或者过度分析您的代码,您是否尝试过将图像标记添加到图像文件名中?
e.g。
function showImages(data) {
for (i = 0; i < data.length; i++) {
var images = data[i];
$("#diretoryImages").append("<li><img src='" + images.toString + "' /></li>");
}
}