MVC4 앱에서 jQuery 파일 업로드 플러그인 (https://github.com/blueimp/jQuery-File-Upload)을 사용하고 있습니다.부분 뷰로드시 jQuery 이벤트가 연결되지 않음
파일 업로드 기능 (업로드 된 파일 및 업로드 된 파일)은 부분보기에 포함되어 있습니다.
그래서 파일 업로드 부분보기가 포함 된 여러 가지보기가 있습니다. 파일이 업로드되면 첨부 컨트롤러의 저장 작업이 시작됩니다. 이것은 파일의 저장을 처리 한 다음 사이트의이 특정 영역에 대한 파일의 업데이트 된 목록을 검색합니다. 뷰는 fileupload jQuery로 리턴 된 다음 Html을 부모 페이지의 div에 삽입합니다 (#_attachments).
이 모든 것이 올바르게 렌더링됩니다. 내가 가지고있는 문제는 파일 업로드가 수행되고 부분 뷰가 jQuery를 통해 다시로드 된 후에 파일 업로드가 더 이상 작동하지 않는다는 것입니다.
이벤트가 더 이상 #fileUpload 컨트롤에 연결되지 않은 것 같습니다. 나는 'on'메쏘드를 사용해 보았지만 이것 역시 효과가없는 것 같습니다.
부분보기 스크립트
$(function() {
$('#fileUpload').fileupload({
url: "/Attachment/Save",
done: function (e, data) {
// "data.result" will contain the response data
$("#fileUploadProgress").hide();
$("#_attachments").html(data.result);
},
progressall: function (e, data) {
var progress = parseInt(data.loaded/data.total * 100, 10);
$("#fileUploadProgress").show();
$("#fileUploadProgress .bar").css("width", progress + "%");
}
});
});
컨트롤러/액션
[HttpPost]
public ActionResult Save()
{
// Get a reference to the file that our jQuery sent. Even with multiple files, they will all be their own request and be the 0 index
HttpPostedFileBase file = HttpContext.Request.Files[0];
int ncpId = Convert.ToInt32(Request.Form["ncpId"]);
int stage = Convert.ToInt32(Request.Form["stage"]);
ncpRepository.SaveAttachmentToDb(file, CurrentUser.UserId, ncpId, stage);
//return the partial view to refresh the list of files
var attachments = ncpRepository.GetAttachmentsForRecord(ncpId);
var attachmentsViewModel = AutoMapper.Mapper.Map<IQueryable<Attachment>, List<AttachmentViewModel>>(attachments);
ViewData["Stage"] = stage;
return PartialView("_StageAttachments", attachmentsViewModel);
}
부분적으로로드 될 때마다 부분 스크립트를 실행하고 있습니까? 여기에 "on"바인더가 필요하지 않을 때마다 매번 fileupload 플러그인을 초기화해야한다고 생각합니다. – Moeri