Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MVC中的拖放功能_Javascript_C#_Jquery_Asp.net Mvc_Razor - Fatal编程技术网

Javascript MVC中的拖放功能

Javascript MVC中的拖放功能,javascript,c#,jquery,asp.net-mvc,razor,Javascript,C#,Jquery,Asp.net Mvc,Razor,在我的MVC应用程序中,我用dropzone拖放功能替换了我的选择文件按钮和上载功能 这是我的javascript @ { var formurl = IGT.baseUrl + "/Items/UploadImageURL"; <script src = "~/Scripts/jquery.filedrop.js" ></script> <script type = "text/javascript" src = "~/Scripts/dropzon

在我的MVC应用程序中,我用dropzone拖放功能替换了我的选择文件按钮和上载功能

这是我的javascript

@ {
  var formurl = IGT.baseUrl + "/Items/UploadImageURL"; 
  <script src = "~/Scripts/jquery.filedrop.js" ></script>
  <script type = "text/javascript" src = "~/Scripts/dropzone/dropzone.js" ></script> 
  <script type = "text/javascript" >
    // Disabling autoDiscover, otherwise Dropzone will try to attach twice.
    Dropzone.autoDiscover = false;
    $(function() {
      // Now that the DOM is fully loaded, create the dropzone, and setup the event listeners
      var myDropzoneImages = new Dropzone("#dropImages", {
        url: '@Url.Action("UploadImage")',
      });
      myDropzoneImages.on("addedfile", function(file) {
        /* Maybe display some more file information on your page */
      });
      myDropzoneImages.on("success", function(file) {
        $(".dz-success-mark svg").css("background", "green");
        $(".dz-error-mark").css("display", "none");
      });
      myDropzoneImages.on("error", function(file) {
        $(".dz-error-mark svg").css("background", "red");
        $(".dz-success-mark").css("display", "none");
      });
    })
  </script>
  <link rel = "stylesheet" type = "text/css" href ="~/Content/DropZone.css" >
}
它按照我想要的方式运行,但是之后转到图片链接会给我一个错误,并且在我的编辑视图页面上我有一个错误

@Html.Raw(Model.imageHtml(640, 480))
它应该显示我刚刚上传的图像,但是它返回这个

如有任何协助,将不胜感激

public ActionResult UploadImage(int ? id) {
  if (id == null)
    return HttpNotFound();
  Item i = db.Items.Find((int) id);
  if (!Directory.Exists(IGT.baseUrl + "/Content/uploads/Item-" + id.ToString()))
    Directory.CreateDirectory(HttpContext.Server.MapPath("~/Content/uploads/Item-" + id.ToString()));
  var fName = "";
  foreach(string fileName in Request.Files) {
    HttpPostedFileBase file = Request.Files[fileName];
    fName = file.FileName;
    if (file != null && file.ContentLength > 0) {
      var image = IGT.contentPath + "\\Items\\";
      if (!System.IO.Directory.Exists(image)) {
        System.IO.Directory.CreateDirectory(image);
      }
      var filename = image + id.ToString() + ".jpg";
      file.SaveAs(filename);
      i.Image_Url = IGT.baseUrl + "/Content/images/Items/" + id.ToString() + ".jpg";
      db.SaveChanges();
    }
  }
  return RedirectToAction("Edit", new {
    id = id
  });
}
@Html.Raw(Model.imageHtml(640, 480))