2016-11-19 5 views
0

나는 여러 파일 게시 작업을하고 있는데, HttpPostedFileBase을 사용 중입니다.파일 HttpPostedFileBase 업로드 지점 부분보기에서 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; } 
} 

부분보기 당신은 당신의 모델 속성의 파일 입력을 생성하지

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

답변

1

@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> 
} 

컨트롤러. 이 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 ... 내 파일을 게시 중입니다. 감사합니다. –