javascript - How to list images from a directory in a div -
my problem this: want pick images diretory, independently of number of them, , list in div through ul/li. have tried below, not showing neither directory name, , directory has 5 pictures. have code in 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); }
and in contactus view, have code:
@{ 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) { (i = 0; < data.length; i++) { var images = data[i]; $("#diretoryimages").append("<li>" + images.tostring + "</li>"); } } </script> <div id = "diretoryimages" />
what doing wrong? guys can me?
you have mistake, not calling function:
images.tostring
add ()
images.tostring()
in particular case don't need call tostring()
, because images variable string:
$("#diretoryimages").append("<li>" + images + "</li>");
Comments
Post a Comment