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();
        }

在控制器中参数始终为空。我错过了什么:/

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 回答