我有同样的问题
@using (Html.BeginForm("CreateRequest","SupportRequest",FormMethod.Post,new { id = "frmstemplate",enctype = "multipart/form-data" })) { <td><input type="file" name="FirstFile" id="FirstFile" class="button" /> <input type="button" class="button" id="FirstFileupload" value="upload" onclick="Javascript:DocumentUpload();"/> } <script language="javascript" type="text/javascript"> function DocumentUpload() { var browseFile = $('#FirstFile').val(); if (browseFile != null && browseFile != "") { alert(browseFile); $.ajax({ type: 'POST',dataType: 'json',url: '@Url.Content("~/SupportRequest/UploadFiles")?fileElementId=' + browseFile,success: function (data) { alert('Hi'); //debugger; if (data.Result == "SUCCESS") { alert('Hi'); } else { ShowInfo('Document Uploaded Successfully'); } } }); } } </script>
在控制器方面,我有:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult UploadFiles(string fileElementId,FormCollection formColl) { var FirstFile = Request.Files; foreach (string upload in Request.Files) { if (!Request.Files[upload].HasFile()) continue; string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/"; string filename = Path.GetFileName(Request.Files[upload].FileName); Request.Files[upload].SaveAs(Path.Combine(path,filename)); } return Json(new { Filename = "" }); }
但是我的Request.Files总是为空.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。