我有一個「Embedded Resource」視圖。在這種觀點我使用下面的模型在「Embedded Resource」視圖中使用「Content」視圖作爲EditorFor模板
public class TestModel
{
public TestModel()
{
CustomModel1 = new CustomModel1();
CustomModel2 = new CustomModel2();
}
public CustomModel1 CustomModel1 { get; set; }
public CustomModel2 CustomModel2{ get; set; }
}
在該視圖中我有一個表格和裏面我使用@Html.EditorFor
代替@Html.Partial
,因爲當我使用@Html.Partial
的CustomModel1傳遞到操作(當窗體提交)是空的。
@Html.EditorFor(m => m.CustomModel1, Constants.CustomEmbeddedView1)
然而,當我使用@Html.EditorFor
,並通過爲模板的「內容」視圖
@Html.EditorFor(m => m.CustomModel1, "~/Views/Common/_CustomPartialView.cshtml")
我收到以下錯誤:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Int32'.
如果我設置的「內容」視圖成爲「嵌入式資源」,一切正常。
有什麼辦法可以解決這個問題嗎?也許有另一種解決方案來解決模型綁定問題,而不是使用@Html.EditorFor
。