You could create an object that can have objects added to it. Given the following:
public class Model1
{
public Model1(){ }
}
public class Model2
{
public Model2(){ }
}
public class Model3
{
public Model3(){ }
}
public class ModelBag
{
public List<object> Models { get; set; }
public ModelBag ()
{
this.Models = new List<object>();
}
public void Add(object obj)
{
if (obj != null) this.Models.Add(obj);
}
public T Get<T>()
{
var found = this.Models.OfType<T>().Select(x=>x);
return (found.Count()>0) ? found.First() : default(T);
}
}
You can do this:
ModelBag bag = new ModelBag();
bag.Add(new Model1());
bag.Add(new Model2());
Model1 bagModel1 = bag.Get<Model1>();
Model3 bagModel3 = bag.Get<Model3>();
In the usage example above, you add model1 and model2 to the bag, and attempt to retrieve either one will result in a non-null reference. Because we didn't add a Model3 object to the bag, trying to retrieve it will result in a null reference.
I leave it as an exercise for the programmer to make the ModelBag suit his needs (allow/disallow duplicates of a given object type.
EDIT ==================================
I wrote an article with a more complete code sample.
Multiple Models In a MVC View[
^]