I have a model A that has the property of another type of model B. I have a view that is attached to A. I want to add a partial view to A, which takes a model of type B. This is my code
public class ModelA { public bool Prop1 {get;set;} public bool Prop2 {get; set;} public Dictionary<int, string> Prop3{get; set;} public int Prop4 {get; set;} public ModelB Prop5 { get; set; } public ModelA () { Prop5 = null; ... more code ... } }
Error: the model element passed to the dictionary is of type "ModelA", but this dictionary requires a model element of type "ModelB"
The line works if I change it to @Html.Partial("FileLinks", new ModelB())
Why is the source code not working? The property is of type ModelB.
Any help is appreciated!
Update: I forgot to add code from the controller
m.FileLinks = new ModelB () return View ("Index", m)
So the model is not null
source share