我有一个模型A有一个属性是另一种模型类型,B.我有一个视图是绑定到A.我想添加一个局部视图到A,它需要B型的模型这是我的代码部分视图模型不能解决
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 ...
}
}
//This view is tied to ModelA
@using (Html.BeginForm("CreateReport", "Home", FormMethod.Post))
{
some markup
}
//this is the problem
@Html.Partial("FileLinks", Model.Prop5) //This line throws an error
Error: The model item passed into the dictionary is of type 'ModelA', but this dictionary requires a model item of type 'ModelB'
线工作,如果我将其更改为@Html.Partial("FileLinks", new ModelB())
为什么没有原代码的工作?该物业属于ModelB型。
任何帮助表示赞赏谢谢!
更新:我忘了从控制器中添加一些代码
m.FileLinks =新ModelB() 返回查看( “指数”,M)
因此模型不为空
发布FileLinks查看请? – Fals