这是我要问的代码示例。
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();
}
如果我在运行时确定模型类型,更新模型的最佳方法是什么?
答案 0 :(得分:1)
要在运行时解决(虽然不明显为什么你需要,从你发布的内容),然后使用dynamic
:
dynamic person = new Person(); // resolves at runtime -- no point in doing this,
// since the type is known at compile time anyway