I have a table with 4 rows (mobile, work, cell, email), and 5+ columns. When I POST I don't get back any data. Can I refactor the code to make it work?
Model:
public class ContactInfoViewModel {
public string HomePhone { get; set; }
public ICollection<bool> HomePhoneChecks { get; set; }
public string MobilePhone { get; set; }
public ICollection<bool> MobilePhoneChecks { get; set; }
public string WorkPhone { get; set; }
public ICollection<bool> WorkPhoneChecks { get; set; }
public string Email { get; set; }
public ICollection<bool> EmailChecks { get; set; }
public string Email2 { get; set; }
public IEnumerable<RowData> Rows { get; set; }
public IEnumerable<RowData> GetAllRows() {
return new List<RowData> {
new RowData { Name = "HomePhone", Label = "Home Phone", Heading = HomePhone, Columns = HomePhoneChecks},
new RowData { Name = "MobilePhone", Label = "Mobile Phone", Heading = MobilePhone, Columns = MobilePhoneChecks},
new RowData { Name = "WorkPhone", Label = "Work Phone", Heading = WorkPhone, Columns = WorkPhoneChecks},
new RowData { Name = "Email", Label = "Email", Heading = Email, Columns = EmailChecks},
};
}
public class RowData {
public string Name { get; set; }
public string Label { get; set; }
public string Heading { get; set; }
public ICollection<bool> Columns { get; set; }
}
View:
@foreach (var row in Model.ContactInfo.GetAllRows()) {
<tr>
<td class="boxRows noMargin">
<div>
<div class="boxLabel">@row.Label</div>
<div class="boxValue">@Html.TextBoxFor(m => row.Heading)</div>
</div>
</td>
@foreach (var item in row.Columns) {
<td>@Html.CheckBoxFor(m => item)</td>
}
</tr>
}