への呼び出しで次の例外が発生しますHtml.RenderPartial。
ディクショナリに渡されたモデル アイテムのタイプは 'ChildClass' ですが、このディクショナリにはタイプ 'ParentClass' のモデル アイテムが必要です。
これら 2 つのクラスは次のように関連しています。
public class ChildClass { /* properties */ }
public class ParentClass
{
    public ChildClass ChildProperty { get; set; }
    /* other properties */
}
ParentClasswhere の値がChildPropertyisのインスタンスがありますnull。
ParentView( ViewUserControl<ParentClass>) とChildView( )の 2 つの部分ビューがありますViewUserControl<ChildClass>。
最初のビューでは、次のように表示されます...
<% Html.RenderPartial("~/Views/Controls/ChildView.ascx", Model.ChildProperty); %>
これは、この投稿の上部に記載されている例外をスローしている行です。
ChildPropertyが null でない場合、正しい機能を確認しました。MVC がこのプロパティの null 値を親型と見なすのはなぜですか?
ChildViewif is not nullのみをレンダリングするコードを追加することで、この問題を回避できChildPropertyますが、この半分ではビューを持つという点が無効になります。