Отображение:
У нас есть сущность, для которой нужна картинка (company), у него есть свой id, по которому мы будем доставать из базы картинку.
В контроллере Company создаем обработчик Image:
public FileContentResult Image(int id)Загрузка картинки:
{
Company c = Repository.Instance.Companies.Single(c => c.ID == id);
if (client == null || client.Logo == null)
return new FileContentResult(new byte[0], "image/gif");
return new FileContentResult(client.Logo.ToArray(), "image/gif");
}
@using (Html.BeginForm("Company_information", "Company", FormMethod.Post, new { id = "frmCompanyInformation", enctype = "multipart/form-data" }))Обработчик:
{
//..
}
public ActionResult CompanyInformation(CompanyInformationModel m, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null && file.ContentLength > 0)
{
MemoryStream ms = new MemoryStream();
file.InputStream.CopyTo(ms);
m.Info.Logo = ms.GetBuffer();
}
Repository.Instance.SaveCompanyInformation(
Repository.Instance.GetClient(Repository.Instance.GetUserID(User.Identity.Name)).ID, m);
}
return RedirectToAction("index");
}
Немає коментарів:
Дописати коментар