I have a view, that is of Inherits from System.Web.Mvc.ViewPage<P>.
Type P has a property of Type C, ie, P could be:
class P
{
public string Name { get; set; }
public C OtherData { get; set; }
}
The View in question is for creating a new P, and as such I want to create a DropDown list of all the available C's.
So the dropdown could be:
- C1
- C2
- C3
- C4
I've tried creating the List<SelectListItem> object for the C's in my controller and then pass them to the view using ViewData but this does not work, as when I try to submit I get the exception:
System.InvalidOperationException: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key C.
So my question is, how do I create a list of C objects to display in my View that inherits from type P. The list of objects is pulled from a database and as such I cannot just simply hardcode the options into the view.
Do I need to create another Model type that marries the 2 types together?