I have the following classes
public class Lookup
{
public int Id { get; set; }
public string Description { get; set; }
...
}
public class AccountTypeLookUp: Lookup
{
...
}
[Serializable]
public class Account
{
[HiddenInput]
public int AccountId { get; set; }
[Required, Display(Name="Account Name", Order=1)]
public string AccountName { get; set; }
[Display(Name="Account Description", Order=2)]
public string AccountDescription { get; set; }
[Required, Display(Name="Institution Name")]
public string InstitutionName { get; set; }
[Required, Display(Name="Account Number"), RegularExpression(@"[0-9]+",ErrorMessage="{0} can only be digits")]
public string AccountNumber { get; set; }
[Display(Name = "Routing Number"), RegularExpression(@"[0-9]+", ErrorMessage = "{0} can only be digits")]
public string RoutingNumber { get; set; }
[Required, Display(Name = "Account Type")]
public AccountTypeLookup AccountType { get; set; }
[ScaffoldColumn(false)]
public List<Transaction> TransactionCollection { get; set;}
public Account()
{
AccountId = default(int);
TransactionCollection = new List<Transaction>();
}
Now in my view I have a combobox which displays the description of Account Type with the values equal to the Id
<select class="input-validation-error" data-val="true" data-val-required="The Account Type field is required." id="AccountType" name="AccountType">
<option value="1">Savings</option>
<option selected="selected" value="2">Checking</option>
<option value="3">CreditCard</option>
</select>
Now how can I bind that comboBox to my local variable
account.AccountType.Id =?
My method signature is
[HttpPost]
public ActionResult Create(Account account)
Currently I get the error "The value '2' is invalid." which makes sense since it is looking for a complex type.