Guest User

Untitled

a guest
Jan 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. @Html.BeginForm("SaveImage", "Listing", FormMethod.Post, new { enctype = "multipart/form-data" }))) {
  2. <div id="modalAddImage" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  3. <div class="modal-header">
  4. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  5. <h3 id="myModalLabel">Modal header</h3>
  6. </div>
  7. <div class="modal-body">
  8. <p>Image</p>
  9. <input type="file" name="file"></input>
  10.  
  11. @foreach (Image translation in Model.Listing.Images)
  12. {
  13. @Html.TextBoxFor(m => m.Description)
  14. }
  15. </div>
  16. <div class="modal-footer">
  17. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  18. <button class="btn btn-primary">Save changes</button>
  19. </div>
  20. </div>
  21. }
  22.  
  23. [HttpPost]
  24. public ActionResult SaveImage(HttpPostedFileBase file)
  25. {
  26. if (file!= null && file.ContentLength > 0)
  27. {
  28. var fileName = Path.GetFileName(file.FileName);
  29. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  30. file.SaveAs(path);
  31. }
  32.  
  33. return View("Maintain");
  34. }
  35.  
  36. [HttpPost]
  37. public ActionResult SaveImage(HttpPostedFileBase file)
  38. {
  39. if (Request.Files.Count > 0)
  40. {
  41. foreach (string upload in Request.Files)
  42. {
  43. if (upload != null)
  44. {
  45. var fileName = Path.GetFileName(file.FileName);
  46. var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
  47. Request.Files[upload].SaveAs(path);
  48.  
  49. }
  50. }
  51. }
  52. return View("Maintain");
  53. }
Add Comment
Please, Sign In to add comment