http://diwakarko.blogspot.com (दिवाकरको ब्लग)

Display All Images from Directory

No comments
Model
public class ImagesModel
    {
        public ImagesModel()
        {
            Images = new List();
        }

        public List Images { get; set; }
    }


Controller
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
Index Display part


@foreach (var src in Model.Images)
{
    

}

No comments :

Post a Comment