我正在尝试将视图中的对象数组传递给控制器,但我没有成功。上传的文件成功从视图传递到控制器,但数组没有。
我的java脚本代码如下所示:
我的控制器代码是:
$("#Btn_ConfirmUpload").click(function (e) {
e.preventDefault();
debugger;
var formData = new FormData();
var uploadeddocument = [];
var deptid = $("#Drp_DepartmentId").find('option:selected').val();
var doctypeid = $("#Drp_DocumentTypeVal").find('option:selected').val();
var doctypename = $("#DocumentTypeText").val();
var jobid = $("#Txt_JobId").val();
var files = $("#DocumentUploader").get(0).files[0];
uploadeddocument.push({
JobId: jobid,
Department: deptid,
DocumentType: doctypename,
DocTypeId: doctypeid,
});
formData.append('UploadedDocument', JSON.stringify(uploadeddocument));
formData.append('DocumentUploader', files);
$.ajax({
url: '@Url.Action("UploadDocument", "Job")',
type: 'POST',
dataType: 'json',
data: formData,
processData: false,
contentType: false,
success: function (data) {
}
});
});
我的模特是这样的:
[HttpPost]
public ActionResult UploadDocument(JobModel data)
{
return View();
}
请帮忙。 提前谢谢。
答案 0 :(得分:0)
更改您的控制器代码,如下所示:
public JsonResult Save()
{
var formData = Request.Form[0];
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
CenterEntity centerModel = javaScriptSerializer.Deserialize<CenterEntity>(formData);
........
}