0
我想从.pdf/.mp4文件发送到jQuery-AJAX的mvc控制器。这里是我的代码 -.pdf/mp4从JQuery-AJAX上传到MVC控制器方法
//JQuery-AJAX
$('#fileUpload').change(function (e) {
var file = e.target.files[0];
fd.append("photos", file);
fd.append("CourseId", courseid);
fd.append("LessonId", lessonid);
$.ajax({
url: '/Admin/Course/SaveFile',
type: 'POST',
data: fd,
cache: false,
contentType: false,
processData: false,
success: handler,
error: handler
});
});
//server-side
public JsonResult SaveFile(IEnumerable<HttpPostedFileBase> photos, FormCollection data)
{
var courseId = data["CourseId"].ToString());
.....
foreach (var file in photos)
{
file.SaveAs(somePath);
}
....
}
但是,如果contentType: false
,请求不会去控制器的方法。
当contentType: "multipart/form-data"
,接着其撞击器的方法,但data["CourseId"]
抛出异常object reference not set ...
但我使用相同的代码很好地上传图片。
任何帮助?
见http://stackoverflow.com/questions/28207106/pdf-file-upload-ajax-html/28257733#28257733 – guest271314 2015-02-07 16:10:18