asp.net mvc 问题 怎么传键值对啊?
asp.net mvc 问题:
我的Model: public class ContactPerson
{
[Key]
[Required(ErrorMessage="Id是必选项!")]
[Display(Name="Contact person Id")]
public int Id{get;set;}
[Required(ErrorMessage="FirstName是必选项!")]
[MaxLength(50,ErrorMessage="FirstName的长度不能大于50!")]
[Display(Name="First Name")]
public string FirstName{get;set;}
[MaxLength(50,ErrorMessage="MiddleName的长度不能大于50!")]
[Display(Name="Middle Name")]
public string MiddleName{get;set;}
[Required(ErrorMessage="LastName是必选项!")]
[MaxLength(50,ErrorMessage="LastName的长度不能大于50!")]
[Display(Name="Last Name")]
public string LastName{get;set;}
[Display(Name="Date of birth")]
[DataType(DataType.Date)]
public DateTime DateOfBirth{get;set;}
[Required(ErrorMessage = "ContactPersonType是必选项!")]
[Display(Name = "Contact person type")]
public int ContactPresonType { get; set; }
//public ContactPersonType ContactPersonType { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual ICollection<EmailAddress> EmailAddresses {get;set;}
public virtual ICollection<PhoneNumber> PhoneNumbers { get; set; }
}
#endregion
我的controler:
public ActionResult Index()
{
//如何返回类别号和对应的类别名的键值对?
IList<ContactPerson> contactPerson = db.ContactPersones.ToList();
return View(contactPerson);
}
但是view上显示:
姓 辈分 名 生日 联系人类别 选择操作
dsaf sadf asdf 2010/10/10 0:00 8 编辑 | 详细 | 删除
其中8是model中的联系人类别号。如8对应公司,9对应联系人啊?
能用键值对么?怎么生成和传递键值对啊?
我的Model: public class ContactPerson
{
[Key]
[Required(ErrorMessage="Id是必选项!")]
[Display(Name="Contact person Id")]
public int Id{get;set;}
[Required(ErrorMessage="FirstName是必选项!")]
[MaxLength(50,ErrorMessage="FirstName的长度不能大于50!")]
[Display(Name="First Name")]
public string FirstName{get;set;}
[MaxLength(50,ErrorMessage="MiddleName的长度不能大于50!")]
[Display(Name="Middle Name")]
public string MiddleName{get;set;}
[Required(ErrorMessage="LastName是必选项!")]
[MaxLength(50,ErrorMessage="LastName的长度不能大于50!")]
[Display(Name="Last Name")]
public string LastName{get;set;}
[Display(Name="Date of birth")]
[DataType(DataType.Date)]
public DateTime DateOfBirth{get;set;}
[Required(ErrorMessage = "ContactPersonType是必选项!")]
[Display(Name = "Contact person type")]
public int ContactPresonType { get; set; }
//public ContactPersonType ContactPersonType { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual ICollection<EmailAddress> EmailAddresses {get;set;}
public virtual ICollection<PhoneNumber> PhoneNumbers { get; set; }
}
#endregion
我的controler:
public ActionResult Index()
{
//如何返回类别号和对应的类别名的键值对?
IList<ContactPerson> contactPerson = db.ContactPersones.ToList();
return View(contactPerson);
}
但是view上显示:
姓 辈分 名 生日 联系人类别 选择操作
dsaf sadf asdf 2010/10/10 0:00 8 编辑 | 详细 | 删除
其中8是model中的联系人类别号。如8对应公司,9对应联系人啊?
能用键值对么?怎么生成和传递键值对啊?
...全文
相关推荐
基于ASP.NET MVC项目实例
**ASP.NET MVC 框架详解**ASP.NET MVC(Model-View-Controller)是一种轻量级、基于组件的Web应用程序架构,它由微软开发并应用于.NET Framework中
详解ASP.NET MVC 下拉框的传值的两种方式
本文主要介绍了ASP.NET MVC框架中下拉框(DropDownList)的两种传值方式,分别通过控制器(Controller)向视图(View)传递数据并进行绑定。在ASP.NET Web
ASP.NET MVC学习笔记-Controller与View传值.
### ASP.NET MVC学习笔记-Controller与View传值#### 一、引言在ASP.NET MVC框架中,数据从Controller传递到View的方式是至关重要的。
ASP.NET MVC 4和ASP.NET MVC5[附源码]合集
**ASP.NET MVC 4** 是ASP.NET MVC框架的一个重要更新,它引入了以下关键特性:1.
ASP.Net+MVC源码
和ASP.NET MVC。


