以下内容将是一种非常整洁的处理方式:
public class AccountModel
{
public string Id { get; set; }
public string Name { get; set; }
public Decimal Balance { get; set; }
public string AccountSummary
{
get
{
return String.Format("{0} ({1:C})", Name, Balance);
}
}
}
public class TransferModel
{
public IList<AccountModel> Accounts { get; set; }
public string SelectedAccountId { get; set; }
/* Whatever other properties your view needs */
}
键入您的视图
TransferModel
并执行:
<%: Html.DropDownListFor(model => model.SelectedAccountId,
new SelectList { Model.Accounts, "Id", "AccountSummary" )%>