1つの基本クラスに2つのクラスがあるとしましょう:
public class BaseModel {
}
そして数人の子供たち:
public class FooModel : BaseModel {
}
public class BarModel : BaseModel {
}
今、私の見解では、次のようなモデルを期待したいと思います:
@model IList<BaseModel>
これらのモデルを 1 ページで編集できるようにします。
ただし、アクションでこれらのモデルのコレクションを渡すと、次のような例外が発生します。
ディクショナリに渡されたモデル項目は、'System.Collections.Generic.List
1[BarModel]', but this dictionary requires a model item of type 'System.Collections.Generic.IList
1[BaseModel]' 型です。
このような:
var models = new List<BaseModel>(){ new BarModel(), new FooModel ()}
return View(models);
どうすればこれを達成できますか?
ありがとう