2016-12-30 3 views
0

신청할 수있는 Job Application 양식이 있습니다. 이 양식을 통해 사람들은 자신의 이력서와 커버 레터를 업로드 할 수 있습니다.Dropzone Js의 모든 업로드 ID를 배열 또는 JSON 집합으로 받으십시오.

Dropzone을 사용하여 여러 파일 (CV 및 표지)을 업로드합니다. 그리고 배열이나 json에 업로드 된 ID 집합을 가져 오려고합니다. 내가 작업 신청서 여기

var idResult = ""; 
    Dropzone.options.uploadDemo = { 
     maxFilesize: 5, //accept file size 5MB 
     paramName: "file", // The name that will be used to transfer the file 
     acceptedFiles: ".pdf,.doc,.docx,.docm,.docb,.dotx,.dotm", //acccept file extension 
     addRemoveLinks: true, 
     init: function() { 
      this.on("success", function (data) { 
       console.log(data); 
       console.log(data.xhr.response); 
       $('#@Html.IdFor(x=>x.Applicant.UploadIds)').val(data.UploadIds); 
      }); 

와 관계를 만드는 데 사용할 수 있도록하는 것은 내 컨트롤러

[HttpPost] 
    [Route("Career/SaveUploadedFile")] 
    public ActionResult SaveUploadedFile() 
    { 
     try 
     { 
      string uploadId = string.Empty; 
      foreach (string fileName in Request.Files) 
      { 
       HttpPostedFileBase file = Request.Files[fileName]; 
       //Save file content goes here 

       if (file != null && file.ContentLength > 0) 

       { 

        var originalDirectory = new DirectoryInfo(string.Format("{0}Upload\\Document", Server.MapPath(@"\"))); 

        string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "file"); 

        var fileName1 = Path.GetFileName(file.FileName); 

        bool isExists = System.IO.Directory.Exists(pathString); 

        if (!isExists) 
         System.IO.Directory.CreateDirectory(pathString); 

        var path = string.Format("{0}\\{1}", pathString, file.FileName); 

        file.SaveAs(path); 


        var upload = TTCHRFacade.CreateUpload(new Upload() 
        { 
         FileName = file.FileName, 
         FileSize = file.ContentLength, 
         FileExtention = file.ContentType, 
         GUIDFileName = Guid.NewGuid().ToString(), 
         UploadDate = DateTime.Now 
        }); 
        uploadId += upload.UploadId.ToString() + ","; 
        //return PartialView("ApplicantUploadTemplate", upload); 
       } 
       else 
       { 
        // Set as bad request (400) 
        Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; 
        ModelState.AddModelError("error", "Need Files."); 
        return Json(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage); 
       } 
      } 
      return Json(new { uploadId }, JsonRequestBehavior.AllowGet); //TODO 

     } 
     catch (Exception ex) 
     { 
      // Set as bad request (400) 
      Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; 
      return Json(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage); 
     } 
    } 

주 : 신청서와 같은보기

감사에 양식을 업로드 사전에. 대신에 하나의 ID의

+0

'data.uploadId'를 아이디의

var uploadIds = new List<string>(); foreach (string fileName in Request.Files) { // Your existing code goes here var uploadId = upload.UploadId.ToString(); uploadIds.Add(uploadId); } //Now return the list of Ids return Json(uploadIds, JsonRequestBehavior.AllowGet); 

의 컬렉션을 반환해야해야 새 이드 줘. – Shyju

+0

예. 그러나 그것은 일련의 이드가 아닙니다. –

+0

ID 배열을 반환 할 수 있습니다. 게시 된 답변보기 – Shyju

답변

0

, 당신은 AJAX 방식의 성공 호출에 전달 된 데이터에이 ID의 배열을 반환합니다

+0

작동하는 것 같습니다. 그러나보기 페이지에서 결과를 반환 할 수 없습니다. : 3 –

+0

보기 페이지에서 결과를 어디로 반환 하시겠습니까? 어떤 결과? – Shyju