无法将数组发回动作方法mvc

时间:2015-02-18 13:43:58

标签: ajax asp.net-mvc

我正在尝试将一个值数组发布回我的action方法,但没有运气,因为我为'ParcelList'获取了一个null。正在填充Upload Files参数,只是ParcelList出现问题。

//ParcelList returning null
 public ActionResult Add(AddShipmentVM model, ParcelVM[] ParcelList, HttpPostedFileBase[] UploadFiles )
    {
        if (ModelState.IsValid)
        {
            return RedirectToAction("Home", "CustomClearence");
        }

        return View(model);
    }

ParcelVM

 public class ParcelVM
 {
    [Required(ErrorMessageResourceType = typeof(AddShipmentVM), ErrorMessageResourceName = "RequiredValue")]
    public string TrackTrace { get; set; }

    [Required(ErrorMessageResourceType = typeof(AddShipmentVM), ErrorMessageResourceName = "RequiredValue")]
    [RegularExpression(@"^\d{0,3}\.?(\d{3,3})*,?\d{1,2}$", ErrorMessageResourceType = typeof(AddShipmentVM), ErrorMessageResourceName = "InvalidWeight")]
    public string GrossWeight { get; set; }

    public decimal Parcelno { get; set; }
 }

的Ajax 当用户点击完成时,提交表单

 $(".actions a[href=#finish]").click(function () {

            var form = jQuery('#addShipmentForm').serializeObject();


            var parcelList = $.parseJSON(ko.toJSON(viewModel.parcelList()));
            var tariffList = $.parseJSON(ko.toJSON(viewModel.tariffList()));
            var dashBoardurl = '@Url.Action("Home","Shipment")'


            var tariffObject = JSON.stringify({ TariffList: tariffList });
    $('#uploadDocument input[type=file]')[0].files }
            var UploadFiles = { UploadFiles: $('#uploadDocument input[type=file]')[0].files }
            $.extend(form, { FinancialAndCustomsModel: tariffObject });
            $.extend(form, { ParcelList: parcelList });
            $.extend(form, UploadFiles);


            $.ajax({
                type: "POST",
                data: form,
                contentType: false,
                success: function (result) {
                    if (result.status == "success") {
                        $(location).attr('href', dashBoardurl);
                    }
                    else {
                        //$(location).attr('href', addRequestUrl);
                    }

                },
                cache: false,
                processData: false

            });
       });

0 个答案:

没有答案