Question

Hi how can I pass additional parameter using jquery fileupload in mvc, the code looks like this :

<label class="imgIcon">
            <span><input type="file" id="fileupload" name="files" multiple="multiple" /></span>
        </label>

$('#fileupload').fileupload({
            dataType: 'json',
            url: '@Url.Action("index")',
            done: function (e, data) {
                $.each(data.result, function (index, file) {
                    $('#homeImg').attr("src","http://localhost:53655/Upload/HomeImages/" + file.name);
                });
            } 
        });

and in controller

 [HttpPost]
            public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
            {
                foreach (var file in files)
                {
                    var filename = Path.Combine(Server.MapPath("~/Upload/HomeImages"), file.FileName);
                    file.SaveAs(filename);
                }
                return Json(files.Select(x => new { name = x.FileName }));
            }
Was it helpful?

Solution

ok I found the answer, it is enoguth to add formData : {name: value}, to request and change signature of the method to one that takes those arquments IEnumerable<HttpPostedFileBase> files, FormCollection forms and then take form forms this additional values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top