我有一個模型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