Display All Images from Directory
Model
Method Index
Index Display part
public class ImagesModel
{
public ImagesModel()
{
Images = new List();
}
public List Images { get; set; }
}
Controller{
public ImagesModel()
{
Images = new List
}
public List
}
Method Index
public ActionResult Index()
{
var images = new ImagesModel();
//Read out files from the files directory
var files = Directory.GetFiles(Server.MapPath("~/Content/img"));
//Add them to the model
foreach (var file in files)
images.Images.Add(Path.GetFileName(file));
return View(images);
}
View{
var images = new ImagesModel();
//Read out files from the files directory
var files = Directory.GetFiles(Server.MapPath("~/Content/img"));
//Add them to the model
foreach (var file in files)
images.Images.Add(Path.GetFileName(file));
return View(images);
}
Index Display part
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment