1

私はこの質問が何度も聞かれることを知っています.答えを探していますが、間違いなく何かが欠けています..

私の見解..

@using TaxiAssistant.Views.CompanyAdmin.Resources

@using (Html.BeginForm("ImportDrivers", "CompanyAdmin", FormMethod.Post, new { enctype = "multipart/form-data" })) {

    <input type="file" name="uploadFile" id="file1" />
    <br />
    <br />
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="@Resources.Import" class="btn btn-default" />
        </div>
    </div> 
}

私のコントローラー:

 [HttpPost]
        public ActionResult ImportDrivers(HttpPostedFileBase file)
        {


            return View();
        }

コントローラー内のパラメーターは常に null です。何が欠けていますか:/

4

2 に答える 2

3

コントロールの名前と一致するようにメソッド パラメーターの名前を変更します。

<input type="file" name="uploadFile" id="file1" />

public ActionResult ImportDrivers(HttpPostedFileBase uploadFile)
{
  ...
于 2014-09-01T22:43:11.467 に答える
1

これをコントローラー内で使用します

file = Request.Files["uploadFile"];

アップロードされたファイルは HttpPostedFileBase のファイルオブジェクトにあります。

于 2015-01-07T11:39:56.320 に答える