1

ファイルのアップロードを処理するコントローラー メソッドを取得しました。

AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(int id, HttpPostedFileBase uploadFile)
{
    if (uploadFile != null && uploadFile.ContentLength > 0 && ...)
    ...
}

Html.BeginForm を使用すると、すべて正常に動作します。Html.BeginForm を Ajax.BeginForm に置き換えると、uploadFile の値が null になります (上記のメソッドの 2 番目のパラメーター)。

<div id="ajaxDocumentUpload">
@{ using (Ajax.BeginForm("FileUpload", "ProjectDocument", FormMethod.Post, 
           new AjaxOptions { OnSuccess = "UploadSuccess" }, 
           new { enctype = "multipart/form-data" }))
  {
    <div>
        <input type=file accept="image/gif, image/jpeg" name="uploadFile">     
    </div>
    <div>
        <input type="hidden" name="id" id="id" value="@Model.ProjectId"/>
    </div>

    <input id=btnUpdateAttachment type=submit value="Upload">
  } 
}
</div>

何が間違っているのですか?助けてくれてありがとう!

4

1 に答える 1

0

に互換性のないパラメータを渡しましたAjax.BeginForm()。代わりにこれを使用してください:

@using(Ajax.BeginForm("FileUpload", "ProjectDocument", null, 
    new AjaxOptions { OnSuccess = "UploadSuccess" }, 
    new { enctype = "multipart/form-data" })

MSDN ドキュメント

于 2013-10-09T09:20:21.000 に答える