I have the following type hierarchy for ClientIndexModel
:
public class ViewModel
{
public virtual IDictionary<string, SelectList> SelectListDictionary
{
get
{
var props = GetType().GetProperties().Where(p => p.PropertyType == typeof(SelectList));
return props.ToDictionary(prop => prop.Name, prop => (SelectList)prop.GetValue(this, null));
}
}
}
public class IndexModel<TIndexItem, TEntity> : ViewModel where TIndexItem : ViewModel where TEntity : new()
{
public List<TIndexItem> Items { get; private set; }
}
public class ClientIndexModel: IndexModel<ClientIndexItem, Client>
{
}
I instantiate in and return a ClientIndexModel
from an ApiController as follows:
public ClientIndexModel Get()
{
var model = new ClientIndexModel();
return model;
}
If I inspect model
with a breakpoint on the return model;
line, the Items
property is present, with a count of 0. Yet the JSON returned from this action only has the SelectListDictionary
property and no Items
property. Why could this be?