Step 1: Create Registration Table.

Create table
- CREATE TABLE [dbo].[Registration1](
- [UserID] [int] IDENTITY(1,1) NOT NULL,
- [Username] [varchar](50) NOT NULL,
- [Password] [varchar](50) NOT NULL,
- [FullName] [varchar](100) NOT NULL,
- [EmailID] [varchar](200) NULL,
- PRIMARY KEY CLUSTERED
- (
- [UserID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
Go to File, then New and click Project. Select ASP.NET MVC 4 Web Application and enter the project name, then click OK, select Empty, select View Engine Razor and press OK.
Step 3: Add model.


user.cs
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace MVCRegistration.Models {
- public class User {
- public int UserID {
- get;
- set;
- }
- [Required(ErrorMessage = "Please provide username", AllowEmptyStrings = false)]
- public string Username {
- get;
- set;
- }
- [Required(ErrorMessage = "Please provide Password", AllowEmptyStrings = false)]
- [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
- [StringLength(50, MinimumLength = 8, ErrorMessage = "Password must be 8 char long.")]
- public string Password {
- get;
- set;
- }
- [Compare("Password", ErrorMessage = "Confirm password dose not match.")]
- [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
- public string ConfirmPassword {
- get;
- set;
- }
- [Required(ErrorMessage = "Please provide full name", AllowEmptyStrings = false)]
- public string FullName {
- get;
- set;
- }
- [RegularExpression(@
- "^([0-9a-zA-Z]([\+\-_\.][0-9a-zA-Z]+)*)+@(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]*\.)+[a-zA-Z0-9]{2,3})$",
- ErrorMessage = "Please provide valid email id")]
- public string EmailID {
- get;
- set;
- }
- }
- }











Prabhat SinghPosted Jul 11, 2019, 6:28 AM
Naren, have a text field like @Html.Password("Code") so want to add min and maximum length but can't do please help asap
Gowtham RajamanickamPosted Jul 9, 2015, 12:29 AM
Good one...