Request.Files [""]回头率空 [英] Request.Files[""] Keep returning null
问题描述
使用uploadify自动提交用户的文件,在我的控制器方法Request.Files [名称]不断返回null的Request.Form,但不为空,我可以看到的Request.Form该文件时,我设置一个断点和调试。我缺少的东西吗?我在MVC2测试这一点,但我打算使用它mvc4。
Using uploadify to auto submit a users files, in my controller method Request.Files["Name"] keeps returning null but request.form isn't null, I can see the file in request.form when I set a breakpoint and debug it. Am I missing something? I'm testing this on mvc2 but i plan on using it on mvc4.
<link href="../../Content/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="../../Scripts/jquery.uploadify.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#file_upload').uploadify({
'swf': '/Content/uploadify.swf',
'uploader': '/Home/UploadFile',
'auto': true
// Your options here
});
});
</script>
</head>
<body>
<%--<% using (Html.BeginForm("UploadFile", "Home", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{ %>--%>
<input type="file" name="file_upload" id="file_upload" style="margin-bottom: 0px" />
<%-- <% } %>--%>
控制器方法:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file)
{
var theFile = Request.Files["file_upload"];
return Json("Success", JsonRequestBehavior.AllowGet);
}
如果我添加一个提交按钮,然后提交它,它会的工作,虽然。我需要汽车虽然没有一个提交按钮。
If I add a submit button and then submit it it will work though. I need to be auto though without a submit button.
推荐答案
IIRC Uploadify
使用 FILEDATA
作为参数。所以:
IIRC Uploadify
uses fileData
as parameter. So:
var theFile = Request.Files["fileData"];
甚至更好:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase fileData)
{
// The fileData parameter should normally contain the uploaded file
// so you don't need to be looking for it in Request.Files
return Json("Success", JsonRequestBehavior.AllowGet);
}
当然,如果你不喜欢这个名字,你可以随时使用 fileObjName
设置。
这篇关于Request.Files [&QUOT;&QUOT;]回头率空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!