asp.net-mvc – 在MVC文件上传中Request.files为空
发布时间:2020-12-15 23:56:33 所属栏目:asp.Net 来源:网络整理
导读:我有同样的问题 @using (Html.BeginForm("CreateRequest","SupportRequest",FormMethod.Post,new { id = "frmStemplate",enctype = "multipart/form-data" })){ tdinput type="file" name="FirstFile" id="FirstFile" class="button" / input type="button"
我有同样的问题
@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总是为空. 我尝试了几件事,比如将代码更改为Request.Files [“FirstFile”]等.每次,文件集合都是空的. 解决方法
您需要在控制器操作参数中使用HttpPostedFileBase才能获取已发布的filedata.
请阅读Phil Haack的完整article (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何在ASP.net c#中的页面之间传递对象而不是值?
- ASP.NET应用程序池回收问题
- ASP.NET FileUpload:如何在选择文件后自动回复?
- asp.net-mvc-4 – 带ID的Html.Actionlink
- asp.net-mvc-3 – MVC站点地??图提供程序 – 在痕迹路径中维
- asp.net-mvc-3 – asp.net mvc 3中的自定义错误页面
- asp.net – AS3将数据传递给ASP
- asp.net-mvc – 为什么要使用视图模型?
- asp.net – SqlFunctions.StringConvert添加不必要的填充
- asp.net-mvc – 使用部分页面的PagedList.MVC中的Ajax分页
推荐文章
站长推荐
- asp.net – 如何使用多个嵌套项反序列化XML?
- asp.net core 系列 5 MVC框架路由(上)
- 将虚拟路径转换为ASP.NET中的实际Web路径
- 在ASP.NET Core中相关的ConfigureAwait(false)?
- asp.net-mvc – 仅为未经过身份验证的用户缓存内
- asp.net – 如何增加Web服务请求的超时?
- ASP.Net HttpHandler ProcessRequest()触发两次
- asp.net-mvc – 即使使用AllowAnonymous,SimpleM
- asp.net-mvc – 如何构建通用存储库
- asp.net-core – 将命名空间添加到ASP.NET MVC 6
热点阅读