Reputation: 5941
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 }));
}
Upvotes: 2
Views: 3415
Reputation: 5941
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.
Upvotes: 4