Im wanting to create an editor for a List of Models which exists as a property in my ViewModel class.
ViewModel class:
public class FooManagementDetailViewModel : ViewModelBase
{
public List<FooPermissionModel> FooPermissions { get; set; }
Model class:
public class FooPermissionModel
{
public string Name { get; set; }
public string Reason { get; set; }
public bool Selected { get; set; }
}
EditorTemplate:
@model FooPermissionModel
<table>
<thead>
<tr>
<th>
Heading
</th>
<th>
Heading
</th>
<th>
Heading
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
@Html.TextBoxFor(x => x.Name, new { @readonly = "readonly" })
</td>
<td>
@Html.CheckBoxFor(x => x.Selected)
</td>
<td>
@Html.TextBoxFor(x => x.Reason)
</td>
</tr>
</tbody>
</table>
View:
<fieldset>
<legend>FooBarTitle</legend>
<div>
@Html.EditorFor(x => x.FooPermissions)
</div>
</fieldset>
What im being returned is a single div of the Names only. No structure at all.
What am i missing?
Thanks!
I have a feeling you may have not specified either your model name correctly or perhaps your EditorTemplate is not being found by MVC.
Note, that the template location for this example is: ~/Views/Shared/EditorTemplates/FooPermissionModel.cshtml
The following shows the EditorTemplate rendering correctly:
Model:
ViewModel:
Controller:
View:
EditorTemplate: