是否可以在MVC 5中对Not Mapped字段使用数据注释验证

时间:2017-04-26 05:23:31

标签: asp.net-mvc viewmodel data-annotations

 public class tblStudentAddress :UpdateDates
{
    [Key]
    public int StudentAddressId { get; set; }
    [ForeignKey("StudentId")]
    public virtual tblStudent tblStudent { get; set; }
    public int StudentId { get; set; }
    [Required(ErrorMessage = "PinCode is required")]
    [RegularExpression(@"^[0-9]{6}", ErrorMessage = "Invalid PinCode")]
    public int StudentPincode { get; set; }

    [NotMapped]

    [RegularExpression(@"^\d{6}(-\d{6})?$", ErrorMessage = "Invalid Zip")]

    public int StudentTempPinCode { get; set; }

StudentTempPincode的值保存为studentAddressTable的下一行,具有相同的studentId(可以添加多个pincodes)。我试过这个显示一些错误,如

  

StudentTempPinCode中的实体验证错误

0 个答案:

没有答案