2

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 }));
            }

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.