我的表格
@using (Html.BeginForm("ViewProjectAssignment", "AssignmentOfProject", FormMethod.Post, new { enctype = "multipart/form-data", @id="formAssignment" }))
{
@Html.AntiForgeryToken()
<table class="headertable">
<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;" })
@Html.ValidationMessageFor(x => x.ProjectName)
</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" })
@Html.ValidationMessageFor(x => x.CEQRNumber)
</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 = "txtFiles" })
@Html.ValidationMessageFor(x => x.File)
</td>
</tr>
<tr>
<td style="padding-left:50px; width:120px;"></td>
<td>
<button name="button" class="button" value="UploadFile" id="btnUploadFiles">
Upload File
</button>
<button name="button" value="create" class="button" id="btnClearSeach">
Clear
</button>
</td>
</tr>
</tbody>
</table>
}
Jquery的
// AntiForgeryToken
var token = $('[name=__RequestVerificationToken]').val();
var headers = {};
headers["__RequestVerificationToken"] = token;
// button click event
$('#btnUploadFiles').click(function (event) {
fnBlockUI();
event.preventDefault();
$.ajax({
url: '@Url.Action("ViewProjectAssignment", "AssignmentOfProject", new { Area = "PrivateCEQRApplication" })',
type: 'POST',
dataType: 'json',
cache: false,
headers: headers,
data: {
ProjectName: $("#ddlProjectName").val(),
CEQRNumber: $("#ddlCEQRNumber").val(),
File: $("#txtFiles").val()
},
beforeSend: function (xhr, settings) { xhr.setRequestHeader('__RequestVerificationToken', token); },
success: function (result) {
$.unblockUI();
$('body').empty().append(result);
},
error: function (xhr, textStatus, errorThrown) {
$.unblockUI();
alert("An error occurred while processing your request. Please try again. If the error persists, please email the account administrator .");
}
});
});
控制器方法
[HttpPost]
public ActionResult ViewProjectAssignment(ProjectUploadFiles uploadFiles)
{
// Upload code here
}
模型
public class ProjectUploadFiles
{
public string CEQRNumber { get; set; }
public string ProjectName { get; set; }
public IEnumerable<HttpPostedFileBase> File { get; set; }
}
问题