0

これが私が求めているコード例です。

    public ActionResult Action()
    {
        object person = new Person(); //It works if i replace object with Person
        UpdateModel(person); //this does not update person because of "object" declaring type

        return View();
    }

実行時にモデルの種類を決定する場合、モデルを更新する最良の方法は何ですか?

4

1 に答える 1

1

実行時に解決するには(ただし、投稿した内容から、必要な理由は明らかではありません)、次を使用しますdynamic

dynamic person = new Person();   // resolves at runtime -- no point in doing this,
                                 // since the type is known at compile time anyway
于 2013-07-13T04:30:29.880 に答える