.pdf/mp4 从 JQuery-AJAX 上传到 MVC 控制器方法

.pdf/mp4 upload from JQuery-AJAX to MVC controller method

我正在尝试将 .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 ...

但我正在使用相同的代码很好地上传图片。

有什么帮助吗?

在 web.config 中添加这些行解决了我的问题-

<system.webServer>
  <security>
    <requestFiltering>
       <requestLimits maxAllowedContentLength="1073741824" />
    </requestFiltering>
  </security>
</system.webServer>