嗨,我如何在 mvc 中使用 jquery fileupload 传递附加参数,代码如下所示:
<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);
});
}
});
并在控制器中
[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 }));
}