C# ASP.NETAjax文件提交模型为空,而变量单独工作正常

C# ASP.NETAjax文件提交模型为空,而变量单独工作正常,c#,asp.net,ajax,razor,C#,Asp.net,Ajax,Razor,我想用ajax上传文件。我有这样一个问题。当我试图接收一个模型时——它是空的,但当我试图将所有内容作为单独的值获取时——它工作正常 public ActionResult UploadImage(HttpPostedFileBase File, string UniqueCode) { // in this case it works } public ActionResult UploadImage(FileUploadModel file){ // in this case th

我想用ajax上传文件。我有这样一个问题。当我试图接收一个模型时——它是空的,但当我试图将所有内容作为单独的值获取时——它工作正常

public ActionResult UploadImage(HttpPostedFileBase File, string UniqueCode)
{
   // in this case it works
}

public ActionResult UploadImage(FileUploadModel file){
  // in this case the model is empty
}
模型看起来怎么样

public class FileUploadModel {
    public string UniqueCode { get; set; }

    [ValidateImage(ErrorMessage = "Please select a PNG image smaller than 3MB")]
    public HttpPostedFileBase File { get; set; }
}
如何发布数据。它对输入变化有效

$(document).on('change', ".preview-input", function(e){
    var blobInfo = $(this)[0].files[0];
    if (blobInfo) {
        let formData = new FormData();
        formData.append('File', blobInfo);
        formData.append('UniqueCode',"TEST");
        $.ajax(
            {
                url: '/files/UploadAttachmentImage',
                type: 'POST',
                cache: false,
                contentType: false,
                processData: false,
                data: formData,
            })
            .success(function (response) { console.log(response); })
            .error(function (response) { console.log(response); }); 
    } else {
        console.log('321');
    }
});
什么是魔法?如何解决这个问题?

c#和.net平台的魔力。这就是为什么我讨厌这种语言。 我所要做的就是在
FileUploadModel模型
上更改
FileUploadModel文件
,一切都开始正常工作