I'm using this plugin: https://github.com/blueimp/jQuery-File-Upload/wiki, the problem is when I click upload and give the button to save it calls a controller, so far so good but when he gives the click the button needs to come some other attributes and I'm not getting to bring these attributes along with the file. Follows the code: /View
$("#anexoUpload").fileupload({
dataType: 'json',
add: function (e, data) {
data.context = $('#salvarAnexo')
.on('click', function () {
data.submit();
$.ajax({
url: "@Url.Action("AdicionarAnexo")",
type: "POST",
cache: false
}).done(function (data) {
});
data.context = $('<p/>').text('Uploading...').appendTo(document.body);
data.submit();
});
},
done: function (e, data) {
alert('Arquivo salvo com sucesso!');
$(".bar").attr("style", "width:0%;")
}
<li id="anexo">
<span>Anexo</span>
<input type="file" name="files[]" id="anexoUpload" />
<div id="progress">
<button id="salvarAnexo">Salvar Anexo</button>
<div class="bar" style="width: 0%;"></div>
</div>
</li>
});
The problem that I believe is in the calling function inside the click fileupload. I'm using this plugin to not need to postback on the page and enter yes only, and when you insert also take two id's to be used for insertion into the database and return the ajax to display a list of attachments.
//Controller
[HttpPost]
public ActionResult AdicionarAnexo()
{
var lista = new List<UploadFilesResult>();
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
}
}
Thanks