如何将dropzone js值从ajax发送到mvc控制器?

时间:2017-01-11 09:10:44

标签: javascript jquery ajax asp.net-mvc dropzone.js

单击按钮时,我需要将名称和dropzone数据发送到控制器

这是我的代码

var officePictures = [];

var elem = $(".dz-details").find("img");

    for (var i = 0; i < elem.length; i++) {

        officePictures.push(elem[i].getAttribute("alt"));

    }

    officePictures = JSON.stringify({ 'officePictures': officePictures });

        $.ajax({
        type: "POST",
        url: "/Office/AddOffice",
        enctype: 'multipart/form-data',
        dataType: "JSON",
        traditional : true, 
        data: {
            OfficeName: $('#Name').val(),
            officePictures : officePictures
        }
    })

实际上工作正常,但我的控制器方法存在问题

Debugger - Dropzone datalist

正如你在图片中看到的那样Dropzone datalist正在进行,但是一个数据是逐个进行的,我该如何解决这个问题?

My Controller code 


[HttpPost]
            [ValidateInput(false)]
            public ActionResult AddOffice(string OfficeName,List<string> officePictures)
            {

                Office office = new Office();
                office.OfficeName = OfficeName;
                db.Office.Add(office);
                db.SaveChanges();

                var lastId = db.Office.OrderByDescending(x => x.ID).Take(1).FirstOrDefault().ID;

                foreach (var item in officePictures)
                {
                    OfficePictures ofp = new OfficePictures();
                    ofp.OfficeID = lastId;
                    ofp.PictureURL = item.ToString();
                    ofp.PictureSEO = "aaa";
                    db.OfficePictures.Add(ofp);
                    db.SaveChanges();
                }

                return RedirectToAction("OfficeIndex", "Office");
            } 

0 个答案:

没有答案