I would like to display all my pictures in my folder \"Images_uploads\" folder into MVC View. So its display on the site. But nothing seems to work..
{
You should probably do this kind of thing in your controller. Use EnumerateFiles to get a listing of all files in a folder:
// controller
public ActionResult MyAction()
{
...
ViewBag.Images = Directory.EnumerateFiles(Server.MapPath("~/images_upload"))
.Select(fn => "~/images_upload/" + Path.GetFileName(fn));
return View(...);
}
// view
@foreach(var image in (IEnumerable)ViewBag.Images))
{
}
Even better, use a strongly-typed view model, like this:
// model
class MyViewModel
{
public IEnumerable Images { get; set; }
}
// controller
public ActionResult MyAction()
{
var model = new MyViewModel()
{
Images = Directory.EnumerateFiles(Server.MapPath("~/images_upload"))
.Select(fn => "~/images_upload/" + Path.GetFileName(fn))
};
return View(model);
}
// view
@foreach(var image in Model.Images)
{
}