Monday, 26 November 2018

Data Annotation in ASP NET MVC C# || Code First Approach Entity Framewor...





using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.ComponentModel.DataAnnotations;

using System.ComponentModel.DataAnnotations.Schema;





namespace WebApplication1.Models

{

    [Table("tbl_user")]

    public class User

    {

        [Key]

        public int UserId { get; set; }





        [Display(Name="Name")]

        [Required(ErrorMessage="*")]

        [StringLength(50,ErrorMessage="Name should contain Atmost 50 characters")]

        [MinLength(3,ErrorMessage="Name should contain Atleast 3 characters")]

        [RegularExpression("^[a-z -']+$",ErrorMessage="Invalid Name")]

        public string Username { get; set; }





        [Display(Name = "Email")]

        [Required(ErrorMessage = "*")]

        [StringLength(50, ErrorMessage = "Email should contain Atmost 50 characters")]

        [MinLength(15, ErrorMessage = "Name should contain Atleast 15 characters")]

        [RegularExpression(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", ErrorMessage = "Invalid Email")]

        public string UserEmail { get; set; }



        [Display(Name = "Date of Birth")]

        [Required(ErrorMessage = "*")]

        [DataType(DataType.Date)]

        public string Userdob { get; set; }





        [Display(Name = "Password")]

        [Required(ErrorMessage = "*")]

        [StringLength(50, ErrorMessage = "Password should contain Atmost 50 characters")]

        [MinLength(6, ErrorMessage = "Password should contain Atleast  6 characters")]

     

        public string userpassword { get; set; }



        [Display(Name = "Confrim Password")]

        [Required(ErrorMessage = "*")]

        [Compare("userpassword",ErrorMessage="Password Does not match...")]

        public string usercpassword { get; set; }





   

   

   

   

   

    }



}

No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...