Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <div class="form-group">
  2. @Html.LabelFor(model => model.Foto, htmlAttributes: new { @class = "control-label col-md-2" })
  3. <div class="col-md-10">
  4. <input type="file" name="ImageData" id="ImageData" />
  5. </div>
  6. </div>
  7.  
  8. [HttpPost]
  9. public ActionResult MakaleOlustur(Makale m, HttpPostedFileBase file)
  10. {
  11. try
  12. {
  13. using (MvcBlogContext context = new MvcBlogContext())
  14. {
  15. Makale _makale = new Makale();
  16. if (file != null && file.ContentLength > 0)
  17. {
  18. MemoryStream memoryStream = file.InputStream as MemoryStream;
  19. if (memoryStream == null)
  20. {
  21. memoryStream = new MemoryStream();
  22. file.InputStream.CopyTo(memoryStream);
  23. }
  24. _makale.Foto = memoryStream.ToArray();
  25. }
  26. _makale.Baslik = m.Baslik;
  27. _makale.OlusturmaTarihi = DateTime.Now;
  28. _makale.Icerik = m.Icerik;
  29. context.Makale.Add(_makale);
  30. context.SaveChanges();
  31. return RedirectToAction("Makale", "Admin");
  32. }
  33. }
  34. catch (Exception ex)
  35. {
  36. throw new Exception("Eklerken hata oluştu" + ex.Message);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement