My formdata is returning undefined in IE9 browser. Sp i am trying to workaround it
Here is what I am trying to do. I am trying to manually append data to formdata if formdata is undefined. But i am not sure how to append multiple files. Help will be greatly appreciated.
Script
$('#btnUploadFiles').click(function (event) {
fnBlockUI();
event.preventDefault();
var data = new FormData($('#formAssignment')[0]);
alert(data);
if (data == undefined)
{
//var data = new FormData();
//var fileLen = $('#txtFile').get(0).files.length;
//alert(fileLen);
//for (var i = 0; i < fileLen; i++) {
// data.append('txtFile[]', $('#txtFile').file[i]);
//}
var ProjectName = $('#ddlProjectName').val();
var CEQRNumber = $('#ddlCEQRNumber').val();
data.append("CEQRNumber", CEQRNumber);
data.append("ProjectName", ProjectName);
};
$.ajax({
url: '@Url.Action("ViewProjectAssignment", "AssignmentOfProject", new { Area = "PrivateCEQRApplication" })',
type: 'POST',
dataType: 'json',
cache: false,
headers: headers,
data: data,
beforeSend: function (xhr, settings) { xhr.setRequestHeader('__RequestVerificationToken', token); },
contentType: false,
processData: false,
success: function (result) {
$.unblockUI();
},
error: function (xhr, textStatus, errorThrown) {
$.unblockUI();
}
});
});
My form
@using (Html.BeginForm("ViewProjectAssignment", "AssignmentOfProject", FormMethod.Post, new { enctype = "multipart/form-data", @id = "formAssignment" }))
{
@Html.AntiForgeryToken()
<table class="headertable">
<thead>
<tr>
<th colspan="2" align="left">
Search Project for Uploading Files
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding-left:50px; width:120px;">
<b>Project Name</b>
</td>
<td>
@Html.DropDownListFor(mod => mod.ProjectName, Model.ProjectNameList, new { @class = "textBoxDisplay", @id = "ddlProjectName", style = "width:300px;" })
<div id="divProjectName" style="display:inline;"></div>
</td>
</tr>
<tr>
<td style="padding-left:50px; width:120px;">
<b>CEQR Number</b>
</td>
<td>
@Html.DropDownListFor(mod => mod.CEQRNumber, Model.CEQRNumberList, new { @class = "textBoxDisplay", @id = "ddlCEQRNumber" })
<div id="divCEQRNumber" style="display:inline;"></div>
</td>
</tr>
<tr>
<td style="padding-left:50px; width:120px;">
<b>Upload File</b>
</td>
<td>
@Html.TextBoxFor(mod => mod.File, new { class = "textBoxFileDisplay", style = "width:600px;", type = "file", multiple = "true", @id = "txtFile" })
<div id="divFile" style="display:inline;"></div>
</td>
</tr>
<tr>
<td style="padding-left:50px; width:120px;"></td>
<td>
@*<input class="button" value="Upload File" type="submit" />*@
<button name="button" class="button" value="UploadFile" id="btnUploadFiles">
Upload File
</button>
</td>
</tr>
</tbody>
</table>
}