我有以下類提前綁定在MVC
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>();
}
現在我認爲我有這顯示帳戶類型的具有等於標識
<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>
值說明現在如何組合框我是否可以將該組合框綁定到本地變量
account.AccountType.Id =?
我的方法簽名是
[HttpPost]
public ActionResult Create(Account account)
目前我收到錯誤「The value'2'is invalid。」這是有道理的,因爲它正在尋找一種複雜的類型。
我正在使用html助手。我只是指向m.AccountType而不是m.AccountType.Id – Mike 2013-04-30 23:14:24