当我想要上传文件时,发送另一个数据字段

时间:2016-09-05 13:23:13

标签: file-upload

我有这个控制器用于上传文件

  1. [HttpPost]
  2. public JsonResult Upload(HttpPostedFileBase uploadedFile)
  3. {
  4. // uploadedFile参数,但是我无法获得其他字段,例如关于文件的新闻
  5. }
  6. 这是我将文件发送到行动的java脚本

    function UploadFile() {
    
        var form = $('#FormUpload')[0];
        var dataString = new FormData(form);
        $.ajax({
            url: '/Home/Upload',  
            type: 'POST',
            xhr: function () {  
                var myXhr = $.ajaxSettings.xhr();
                if (myXhr.upload) {  
                    //myXhr.upload.onprogress = progressHandlingFunction
                    myXhr.upload.addEventListener('progress', progressHandlingFunction, false); // For handling the progress of the upload
                }
                return myXhr;
            },
            //Ajax events
            success: successHandler,
            error: errorHandler,
            complete:completeHandler,
            // Form data
            data: dataString,
            //**********
            //i want send another filed with datastring but i can not
    
            //**********
            //Options to tell jQuery not to process data or worry about content-type.
            cache: false,
            contentType: false,
            processData: false
        });
    
    }

    这是我的观看代码 enter image description here

    我希望将带有上传文件的textarea内容发送到操作 坦

0 个答案:

没有答案