2016-11-19 11 views
0

私は複数のファイルの投稿に取り組んでいます、私はHttpPostedFileBaseを使用しています。ファイルHttpPostedFileBase upload投稿部分ビューのNULL MVC

フォームを送信する場合、fileプロパティはnullです。

モデル

public partial class Driver 
{ 
    public int DriverId { get; set; } 
    public string DriverFirstName { get; set; } 
    .... 
    public List<DriverImages> DriverImages { get; set; } 
} 

public class DriverImages 
{ 
    public int DriverImageID { get; set; } 
    public string ImagePath { get; set; } 
    public string Description { get; set; } 
    public HttpPostedFileBase file { get; set; } 
} 

パーシャルビュー

@model DataModel.DriverImages 
... 
@using (Design.Common.HtmlPrefixScopeExtensions.BeginCollectionItem(this.Html, "DriverImages")) 
{ 
    <table> 
     <tr> 
      <td> 
       @Html.TextBoxFor(m => Model.Description) 
      </td> 
      <td> 
       <input type="file" name="file" /> 
      </td> 
     </tr> 
    </table> 
} 

コントローラ

[httppost] 
public ActionResult Create(Driver ObjDriverModel, HttpPostedFileBase[] files) 
{ 
    // ObjDriverModel.DriverImages.file // always null 
} 

答えて

1

あなたのモデルプロパティのファイル入力を生成しません。それは、これはxxxGuid

ある

<input type="file" name="DriverImages[xxx].file" .... /> 

を生成し、あなたがそれらを受け取っただろうに注意してください(あなたの方法からHttpPostedFileBase[] fileパラメータを削除します

<td> 
    @Html.TextBoxFor(m => m.Description) 
</td> 
<td> 
    @Html.TextBoxFor(m => m.file, new { @type = "file" }) 
</td> 

にする必要がありますが、パラメータの名前を変更しましたプロパティ名と一致するfileに変更しますが、ファイル入力が空の場合はモデルに一致しません)。

+0

greattt help ...そのファイルを投稿しています。 –

関連する問題