Asp.net mvc MVC DropDownList用于获取2个名称
嗨,我正在为学校作业开发一个银行系统。您能否在dropdownlist ex中传递2个名称: 这就是模型Asp.net mvc MVC DropDownList用于获取2个名称,asp.net-mvc,variables,html.dropdownlistfor,Asp.net Mvc,Variables,Html.dropdownlistfor,嗨,我正在为学校作业开发一个银行系统。您能否在dropdownlist ex中传递2个名称: 这就是模型 public TransferModel(int bankId, int userid) { myAccount = new Service1Client().getAccountByID(bankId); AccountList = new SelectList(new Service1Client().RetrieveAllAccountsByAccountId(user
public TransferModel(int bankId, int userid)
{
myAccount = new Service1Client().getAccountByID(bankId);
AccountList = new SelectList(new Service1Client().RetrieveAllAccountsByAccountId(userid), "Id", "Name");
}
我正在将Id、名称设置到选择列表
视图:
退出:model.myAccount.Id,model.AccountList)%>
选择列表将仅显示帐户的名称。是指他们随时可以在下拉列表中显示姓名和余额
谢谢以下类似的方式将是一种相当整洁的处理方式:
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 */
}
可能重复。请在此处检查答案:
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 */
}
<%: Html.DropDownListFor(model => model.SelectedAccountId,
new SelectList { Model.Accounts, "Id", "AccountSummary" )%>