I have the following view models:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public BankAccount BankAccount { get; set; }
public PayPalAccount PayPalAccount { get; set; }
}
public class BankAccount
{
public string BankName { get; set; }
public string AccountNumber { get; set; }
}
public class PayPalAccount
{
public string PayPalEmail { get; set; }
}
In my single view I have a form that binds the Person
model and also has a DropDownList
that let's the user choose an account type.
Once the user makes his choice, I load dynamically using jQuery ajax one of the partial views that represent either the BankAccount
or the PayPalAccount
and I add it to the page.
After the user clicks submit, I call this action:
public ActionResult Save(Person person)
{
// Here I expect that either person.BankAccount or person.PayPalAccount
// will contain the user input, and the other will be null
}
How do I make the partial view properties bind to the nested property in my Person
view model?