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 回答