Freshblood
Freshblood

Reputation: 6441

UpdateModel does not work when declaring type is different

Here is code example of what i am asking.

    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();
    }

What is best way to update model if if i determine model type at runtime ?

Upvotes: 0

Views: 106

Answers (1)

McGarnagle
McGarnagle

Reputation: 102793

To resolve at runtime (although not evident why you'd need to, from what you've posted), then use dynamic:

dynamic person = new Person();   // resolves at runtime -- no point in doing this,
                                 // since the type is known at compile time anyway

Upvotes: 1

Related Questions