从视图模型中排除属性

时间:2013-05-22 07:02:28

标签: asp.net-mvc c#-4.0

我有一个包含CustomerModel的viewmodel,例如

 public class MyAccountViewModel
{
    public CustomerModel Customer { get; set; }
    public LoginModel Login { get; set; }
    public ICollection<AuthenticationClientData> Clients { get; set; }
    public bool HasLocalPassword { get; set; }
    public LocalPasswordModel Password { get; set; }
}

  [DataContract]
public class CustomerModel
{
    [DataMember]
    public Guid CustomerBusinessId { get; set; }

    [DataMember(IsRequired = true)]
    [Required(ErrorMessage = "First Name is required")]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }

    [DataMember(IsRequired = true)]
    [Required(ErrorMessage = "Last Name is required")]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }


    [DataMember]
    public string FullName
    {
        get { return string.Format("{0} {1}", FirstName, LastName); }
    }

    [DataMember]
    public string Identity { get; set; }

    [DataMember(IsRequired = true)]
    [Required(ErrorMessage = "Email is required")]
    public string Email { get; set; }


    [DataMember]
    [Display(Name = "Birth Date")]
    public DateTime? BirthDate { get; set; }

    [DataMember]
    public string Mobile { get; set; }

    [DataMember]
    public string Phone { get; set; }

    [DataMember]
    public string Twitter { get; set; }

    [DataMember]
    [Display(Name = "Facebook")]
    public string FaceBook { get; set; }

    [DataMember]
    public string WebSite { get; set; }

    [DataMember]
    public string Blog { get; set; }

}

我的CustomerModel对象包含一个属性&#34; CustomerBusinessId&#34;我的viewmodel是否可以排除此属性,因此我只将所需的字段返回给视图?

0 个答案:

没有答案