웹 사이트에 ASP.NET MVC 4를 사용하고 있으며 내가 만드는 작업 중 하나는 CSV 가져 오기입니다. ORM의 속성에 CSV 열을 매핑하고 싶습니다. 파일을 업로드 한 후 열 번호, 첫 번째 줄 (csv 파일의 헤더 포함) 및 두 번째 줄 (데이터 미리보기)을 표시하려고합니다.빈 ViewModel이 뷰에서 반환되었습니다.
/// <summary>
/// The mapping view model.
/// </summary>
public class MappingViewModel
{
#region Public Properties
/// <summary>
/// Gets or sets the mappings.
/// </summary>
public IList<Mapping> Mappings { get; set; }
public MappingViewModel()
{
//this.Mappings = new List<Mapping>();
}
public string FileName { get; set; }
#endregion
}
/// <summary>
/// The mapping.
/// </summary>
public class Mapping
{
#region Public Properties
public int ColumnIndex { get; set; }
public string ColumnHeader { get; set; }
public string DataPreview { get; set; }
public string PropertyIdentifier { get; set; }
#endregion
}
모델 내부의 목록을 나는 루프는 다음과 같이 어디 강력한 형식의 면도기보기를 만들었습니다
@model MappingViewModel
@using (Html.BeginForm("ApplyMapping", "Person"))
{
@Html.EditorFor(t=>t.FileName)
<table class="i-table fullwidth">
<thead>
...table header
</thead>
@foreach (var mapping in Model.Mappings)
{
<tr>
<td>@Html.EditorFor(x=>mapping.ColumnIndex)</td>
<td>@Html.EditorFor(x => mapping.ColumnHeader)</td>
<td>@Html.EditorFor(x => mapping.DataPreview)</td>
<td>@Html.DropDownListFor(x=>mapping.PropertyIdentifier,(SelectList)ViewBag.PropertyList)</td>
</tr>
}
</table>
<input type="submit" value="@Resources.Default.ButtonSaveText" class="icon16-button forms-16" />
}
을 그리고 나를 위해 작동하지 않습니다. 데이터는 표시되지만받는 컨트롤러 동작에는 파일 이름을 제외한 빈 모델이 표시됩니다.
내가 뭘 잘못하고 있니?
P. 동작은 다음과 같습니다.
ApplyMapping actionResult의 중단 점에서 viewmodel props를 읽습니다. 중단 점이 발생할 때 - 파일 이름이 올바르게 설정되면 목록은 NULL입니다.
안녕하세요 호르헤, 그들은 양식 안에 있고 나는 그들을 EditFor로 바꿨지 만, 그 변화는 아무 것도 변하지 않습니다. 여전히 파일 이름은 뷰에서 되돌아 오지만 목록은 null을 반환합니다 –