我的视图中有一个文件
<form id="upload" enctype="multipart/form-data">
<input type="file" name="fileUpload" id="fileUpload" size="23" />
</form>
Run Code Online (Sandbox Code Playgroud)
和ajax请求
$.ajax({
url: '<%=Url.Action("JsonSave","Survey") %>',
dataType: 'json',
processData: false,
contentType: "multipart/mixed",
data: {
Id: selectedRow.Id,
Value: 'some date was added by the user here :))'
},
cache: false,
success: function (data) {}
});
Run Code Online (Sandbox Code Playgroud)
但Request.Files中没有文件.ajax请求有什么问题?
我正在为客户端编写 C# ASP.Net MVC 应用程序以将文件发布到其他服务器。我正在使用通用处理程序来处理从客户端到服务器的发布文件。但在我的处理程序中, System.Web.HttpContext.Current.Request.Files 始终为空(0 计数)。
表格代码:
@model ITDB102.Models.UploadFileResultsModels
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
<h1>Upload File</h1>
<form id="file-form" action="/Files/UploadFile" method="post" data-ajax="false" enctype="multipart/form-data">
<div><input type="file" id="FilePath" name="FilePath"/>
<button type="submit">Send File</button></div>
</form>
</div>
@section scripts{
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
// Variable to store your files
var files;
var form = document.getElementById('file-form');
// Add events
$('input[type=file]').on('change', prepareUpload);
// Grab the files and set them to our variable
function prepareUpload(event) {
files = $('#FilePath').get(0).files;
}
form.onsubmit = function (event) {
uploadFiles(event); …Run Code Online (Sandbox Code Playgroud)