Lets say I have two classes one base class:
public class BaseModel {
}
And a couple of children:
public class FooModel : BaseModel {
}
public class BarModel : BaseModel {
}
Now my view I would like to expect a model like this:
@model IList<BaseModel>
So that I can edit these models on one page.
However when I pass in a collection of these models in the action I get an exception saying:
The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[BarModel]', but this dictionary requires a model item of type 'System.Collections.Generic.IList
1[BaseModel]'.
Like this:
var models = new List<BaseModel>(){ new BarModel(), new FooModel ()}
return View(models);
How can I achieve this?
Thanks