2011-03-28 2 views
2

필자는 fileuploadfield를 포함하는 간단한 ExtJs 양식 패널을 가지고 있습니다. 양식을 서버에 제출하면 모든 키 값 양식 값이 서버로 보내지지만 파일 업로드 필드의 키 값 쌍은 보내지 않습니다. 이것이 누구인지 아는 사람이 있습니까? (아래에 일부 코드 조각을 첨부했습니다)ASP.NET MVC를 사용하여 서버에서 ExtJs 'fileuploadfield'를 처리합니까?

또한 서버에서 업로드를 어떻게 처리합니까? 즉 이미지를 서버 프로세스에 업로드하여 서버의 어딘가에 저장하고 싶습니다.

public JsonResult SetEmployeeDetails(string firstname, string photopath) 
    { 
     GetData data = delegate 
     { 
      return Repo.SetEmployeeDetails(firstname, photopath); 
     }; 
     JsonResultBase jsonResult = GetJsonResult(data); 
     JsonResult json = PortalJsonResult(jsonResult, JsonRequestBehavior.AllowGet); 
     return json; 
    } 



xtype: 'form', 
title: 'Employee Setup', 
items: [{ 
      fieldLabel: 'Firstname', 
      xtype: 'textfield', 
      name: 'firstname', 
      maxLength: 10, 
      allowBlank:false 
     }, 
     { 
      xtype: 'fileuploadfield', 
      id: 'form-file', 
      emptyText: 'Select an image', 
      fieldLabel: 'Photo', 
      name: 'photopath', 
      buttonText: '', 
      buttonCfg: { 
       iconCls: 'upload-icon' 
      } 
     }], 
buttons: [{ 
    text: 'Save', 
    scope: this, 
    handler: function(){ 
     var form = this.items.items[0].getForm(); 
     if(form.isValid()){ 
      form.submit({ 
       url: 'EmployeeDetails/SetEmployeeDetails', 
       waitMsg: 'Saving your details...', 
       success: function(fp, o){ 
        msg('Success', 'Processed file on the server'); 
       } 
      }); 
     } 
    } 
}] 

답변

4

파일 메서드 매개 변수를 가져올 수 없습니다. 따라서 photopath 변수는 보통 null이됩니다.

HttpPostedFileBase postedFile = Request.Files["fileinput"]; 
if (postedFile != null) 
{ 
    //process the file content using postedFile.InputStream... 
} 

를 그리고 자바 스크립트는 ExtJS에 당신이 형태의 파일을 업로드하는 알 수 있도록 양식 설정에 fileUpload: true,을 추가해야 는 다음을 수행 할 수 있습니다, 업로드 된 파일에 액세스합니다.

1

비슷한 문제가있었습니다. 파일 업로드를 처리하는 페이지에서 콘텐츠 유형을 "text/html"로 설정해야한다는 것을 알았습니다. :-(

Response.ContentType = "text/html"; 

당신은 당신이

서버 응답이 IFRAME에 대한 문서를 만들 브라우저에 의해 해석되는 것을 볼 수 read the documentation for Ext.data.Connection,합니다. 서버가 반환 객체를 보낼 JSON을 사용하는 경우 브라우저가 텍스트를 변경하지 않고 문서 본문에 삽입하도록 Content-Type 헤더를 "text/html"로 설정해야합니다.

귀하의 질문에 대해 다른 사람이 에 유사한 문제로에!

잘하면이 도움이 될 것입니다!

관련 문제