MVC4的数据注释

时间:2013-07-18 09:24:51

标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 data-annotations

问题是,我想在POCCO Enitites中实现数据注释但是在“edmx update”之后我所有的验证都被删除了,为了做到这一点,我做了R& D,但是没有成功。我和你们所有人分享了我的谢里奥,请有人回答。

POCCO实体

namespace FGSMVC
{
    using System;
    using System.Collections.Generic;

    public partial class DeclaredBill
    {
        public DeclaredBill()
        {
            this.DeclaredBillReciepts = new HashSet<DeclaredBillReciept>();
        }

        public string DocNo { get; set; }
        public string BCCode { get; set; }
        public string BillNo { get; set; }
        public Nullable<System.DateTime> BillDate { get; set; }
        public string PONumber { get; set; }
        public string CustomerCode { get; set; }
        public Nullable<double> Amount { get; set; }
        public bool IsPaid { get; set; }
        public bool IsActual { get; set; }

        public virtual BusinessConcern BusinessConcern { get; set; }
        public virtual ICollection<DeclaredBillReciept> DeclaredBillReciepts { get; set; }
        public virtual PartyDetail PartyDetail { get; set; }
    }
}

我的模特班

namespace FGSMVC.Models
{
    [MetadataType(typeof(DeclaredBillModel))]
    public partial class DeclaredBill
    {
    }

    public class DeclaredBillModel
    {

        [Display(Name = "Doc No")]
        public string DocNo;

        [Display(Name = "Business Concern")]
        public string BCCode;

        [Display(Name = "Bill #")]
        public string BillNo;

        [Display(Name = "Bill Date")]
        public Nullable<System.DateTime> BillDate;

        [Display(Name = "PO #")]
        public string PONumber;

        [Display(Name = "Customer")]
        public string CustomerCode;

        [Display(Name = "Amount")]
        public Nullable<double> Amount;

        [Display(Name = "Paid")]
        public bool IsPaid;

        [Display(Name = "Acutal")]
        public bool IsActual;
    }
}

As result is given below


请有人解决我的问题,我遇到麻烦, 在我看来,标签必须显示为显示名称数据注释

1 个答案:

答案 0 :(得分:1)

尝试在元数据类中使用自动属性而不是序数字段(DeclaredBillModel):

[Display(Name = "Doc No")]
public string DocNo {get;set;}

这是另一个问题......部分类(DeclaredBill)无法在2个不同的名称空间中定义。使用您的代码,您定义了两个不同的DeclaredBill类,并且只有其中一个(不是您在View中使用的那个)具有注释。所以移动你的代码:

[MetadataType(typeof(DeclaredBillModel))]
public partial class DeclaredBill
{
}

命名空间 FGSMVC ,来自 FGSMVC.Models