Я пытаюсь отобразить изображения, которые я загружал ранее, но безуспешно.
Изображения загружены, это точно. Пока я написал что-то вроде этого:
@if(Model.AttachedInformation.Count > 0)
{
<div id="gallery">
@foreach(var path in Model.AttachedInformation)
{
<img src="@path" alt="default_description" title="some_title" />
}
</div>
}
AttachedInformation
- это просто ICollection<String>
объект.
Но это дает мне только границы изображений. Кроме того, я проверил @path
переменную, и она действительно хранит полные пути к файлам.
Предложения приветствуются!
Спасибо!
РЕДАКТИРОВАТЬ: КОНТРОЛЛЕР
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Employee employee, IEnumerable<HttpPostedFileBase> files)
{
if(ModelState.IsValid)
{
var filepath = String.Empty;
foreach(var file in files)
{
if(null != file && file.ContentLength > 0)
{
filepath = Path.Combine(
HttpContext.Server.MapPath("~/Content/Images/Uploads"),
Path.GetFileName(file.FileName)
);
file.SaveAs(filepath);
employee.AttachedInformation.Add(filepath);
}
}
this.repository.Add(employee);
return Redirect("/");
}
else
{
return View(employee);
}
}
MODEL
AbstractEntity
сохраняет свойства Version
и ID
.
[Serializable]
public class Employee : AbstractEntity<Employee>, IAggregateRoot
{
public Employee()
{
this.AttachedInformation = new HashSet<String>();
}
public virtual String FirstName { get; set; }
public virtual String MiddleName { get; set; }
public virtual String LastName { get; set; }
public virtual String SSN { get; set; }
public virtual String EmployeeNumber { get; set; }
public virtual String TradeUnionNumber { get; set; }
public virtual String Department { get; set; }
public virtual String Post { get; set; }
public virtual DateTime DateOfHire { get; set; }
public virtual DateTime DateOfBirth { get; set; }
public virtual ICollection<String> AttachedInformation { get; set; }
}
VIEW
Представление содержит несколько input
с именем files
, например:
<input type="file" name="files" id="additional" class=" " accept="image/jpeg,image/png,image/gif" />
RAW HTML
<div id="gallery">
<img src="D:\Programming.Projects\BOA\branches\BOA.PresentationLayer\Content\Images\Uploads\Desert.jpg" alt="default_description" title="some_title" />
<img src="D:\Programming.Projects\BOA\branches\BOA.PresentationLayer\Content\Images\Uploads\Hydrangeas.jpg" alt="default_description" title="some_title" />
<img src="D:\Programming.Projects\BOA\branches\BOA.PresentationLayer\Content\Images\Uploads\Jellyfish.jpg" alt="default_description" title="some_title" />
<img src="D:\Programming.Projects\BOA\branches\BOA.PresentationLayer\Content\Images\Uploads\Koala.jpg" alt="default_description" title="some_title" />
</div>
BOUNTY
Мне нужно получить иллюстрированный пример (это работает). Спасибо!