0

uploadify を使用してユーザー ファイルを自動送信します。コントローラー メソッド Request.Files["Name"] で null を返し続けますが、request.form は null ではありません。 . 何か不足していますか?これを mvc2 でテストしていますが、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);
    }

送信ボタンを追加して送信すると、機能します。送信ボタンがなくても自動である必要があります。

4

1 に答える 1

2

IIRCUploadifyfileDataパラメーターとして使用します。そう:

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設定を使用していつでもカスタマイズできます。

于 2012-12-13T22:14:36.710 に答える