如何将json对象和formdata传递给mvc控制器

时间:2018-09-08 09:48:05

标签: jquery json ajax

 var fileUpload = $("#exampleInputFile").get(0);    
        var files = fileUpload.files;
        var fileData = new FormData(); // Create FormData object
        for (var i = 0; i < files.length; i++) { // Looping over all files and add it to FormData object
            fileData.append(files[i].name, files[i]);            
        }


        var customer = { Name: $("#Name").val(), Address: $("#Address").val() };         
            $.ajax({
                type: 'POST',
                data: JSON.stringify({ personViewModel: customer ,httpPosted:formData}),
                async: false,
                url: 'Customer/SaveCustomer',
                contentType: 'application/json',

嗨, 所以我的问题是,如果我在下面的代码不起作用,则请求为空数据:JSON.stringify({personViewModel:customer,httpPosted:formData}), 那么正确的对齐方式是什么?我应该在哪里放置httpPosted:formData

我的控制器在下面

public ActionResult SaveCustomer(CustomerViewModel personViewModel,HttpPostedFileBase httpPosted){
var x = Request is empty
}

0 个答案:

没有答案