Showing posts with label Registration Page Using MVC. Show all posts
Showing posts with label Registration Page Using MVC. Show all posts

Monday, 5 June 2017

Registration Page Using MVC

Registration Form & Bind Grid view Using MVC

Step 1st :- Use SQL Server


-- Create Table 


CREATE TABLE UserNewReg
(
Name varchar(50),
Gender varchar(50),
EmailId varchar(50) primary key ,
Password varchar(50),
MobileNo varchar(50)
);

Step 2nd :- Use Visual Basic 2013

--- Create Emplty MVC Project (VijayMVCWebApp)




1--- First Create Model Class



2----Second  Add Validation (UserNewReg.cs)


 public partial class UserNewReg
    {

        [Required(ErrorMessage = "Enter Name.")]
        public string Name { get; set; }

        [Required(ErrorMessage = "Enter Gender.")]
        public string Gender { get; set; }

        [Required(ErrorMessage = "Enter  Email-id.")]
        [EmailAddress(ErrorMessage = "Invalid email address.")]
        public string EmailId { get; set; }

        [Required(ErrorMessage = "Enter Password.")]
        public string Password { get; set; }

        [Required(ErrorMessage = "Enter MobileNumber.")]
        public string MobileNo { get; set; }

    }



3---- Add Controller ("HomeContoller")




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VijayMVCWebApp.Models;

namespace VijayMVCWebApp.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

        //Create Object of DataBase
        DotNetDBEntities db = new DotNetDBEntities();

         //For New Registration
        public ActionResult NewUserAdd()
        {
            return View();
        }

        //Save New USer
        [HttpPost]
        public ActionResult NewUserAdd(UserNewReg emp)
        {
            db.UserNewRegs.Add(emp);
            db.SaveChanges();
            return View();
        }

       //Show User GridView
        public ActionResult UserGridList()
        {
            return View(from user in db.UserNewRegs.Take(10)
                        select user );
            //return View();
        }


    }
}


Note :- Create View as exaple As below Image




eg.:-Code of View(Bind Gridview)  UserGridList.cshtml


@model IEnumerable<VijayMVCWebApp.Models.UserNewReg>

@{
    ViewBag.Title = "UserGridList";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>UserGridList</h2>

<table cellpadding="0" cellspacing="0" class="table">
    <tr>
        <th>Name</th>
        <th>Gender</th>
        <th>EmailId</th>
        <th>Password</th>
        <th>MobileNo</th>
    </tr>
    @foreach (var user in Model)
    {
        <tr>
            <td>@user .Name</td>
            <td>@user .Gender</td>
            <td>@user .EmailId</td>
            <td>@user .Password</td>
            <td>@user .MobileNo</td>
        </tr>
    }
</table>


-----------------------------------------------------------------
OUTPUT
-----------------------------------------------------------------
1:- Registration form with validation


2:-User Bind  Gridview 


Factorial of a Number

Recently Viewed