Request.Files [""]回头率空

编程入门 行业动态 更新时间:2024-10-20 18:53:18
本文介绍了Request.Files [""]回头率空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用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="code.jquery/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;]回头率空

本文发布于:2023-11-24 23:01:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627241.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回头率   Request   Files   QUOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!