使用 mvc4 将图像显示为移动应用程序的幻灯片。
我将这些图像的物理路径放入一个受控制的数组 [] 中。我想将该数组传递给查看。我想将这些图像显示为幻灯片。
这是我的代码
控制器代码:
public ActionResult Index()
{
var imageFiles = new Mobile.Models.DisplayImages.ImageModel();
imageFiles.Images.AddRange(System.IO.Directory.GetFiles(@"E:\05-11\New Folder\Images\BannerImages\"));
for (int i = 0; i < imageFiles.Images.Count; i++)
{
// get rid of the fully qualified path name
imageFiles.Images[i] = imageFiles.Images[i].Replace(@"E:\05-11\New Folder\Images\BannerImages\", "../../Images/BannerImages/");
// change the slashes for web
imageFiles.Images[i] = imageFiles.Images[i].Replace('\\', '/');
}
return View(imageFiles);
}
型号代码:
public class DisplayImages
{
public class ImageModel
{
List<string> _images = new List<string>();
public ImageModel()
{
_images = new List<string>();
}
public List<string> Images
{
get { return _images; }
set { _images = value; }
}
}
}
查看代码:
@for (int imgIndex = 0; imgIndex < Model.Images.Count; imgIndex++){
if (imgIndex == 0)
{
<img class="first" src = "@Model.Images[imgIndex]" alt="No Image"/>
}
else
{
<img src = "@Model.Images[imgIndex]" alt="No Image"/>
}
}
您可以根据需要在视图文件中应用样式。