1.5.1.Adding validation

  • 1.Add data annotation to the model

    public class Customer
    {
        public int Id{ get; set; }

        [Required]
        [StringLength(255)]
        public string Name { get; set; }

        public bool IsSubscribeToNesletter { get; set; }

        public MembershipType membershipType { get; set; }

        [Display(Name = "Membership Type")]
        public byte membershipTypeId { get; set; }

        [Display(Name = "Date or Birth")]
        public string Birthday { get; set; }
    }
  • 2.Add ModelState in the controller

  • 3.Add warning message to the view

Last updated

Was this helpful?