Create Signup form using Entity Framework – Database First Approach
Database Table Contain following columns
-UserName
-Contact
-Password
@model Registration.Models.tblRegistration
@ {
Layout = null;
} <
!DOCTYPE html >
<
html >
<
head >
<
meta name = "viewport"
content = "width=device-width" / >
<
title > Index < /title> <
/head> <
body >
@using(Html.BeginForm()) {
@Html.AntiForgeryToken()
<
div class = "form-horizontal" >
<
h4 > tblRegistration < /h4> <
hr / >
@Html.ValidationSummary(true, "", new {
@class = "text-danger"
}) <
div class = "form-group" >
@Html.LabelFor(model => model.FName, htmlAttributes: new {
@class = "control-label col-md-2"
}) <
div class = "col-md-10" >
@Html.EditorFor(model => model.FName, new {
htmlAttributes = new {
@class = "form-control"
}
})
@Html.ValidationMessageFor(model => model.FName, "", new {
@class = "text-danger"
}) <
/div> <
/div> <
div class = "form-group" >
@Html.LabelFor(model => model.LName, htmlAttributes: new {
@class = "control-label col-md-2"
}) <
div class = "col-md-10" >
@Html.EditorFor(model => model.LName, new {
htmlAttributes = new {
@class = "form-control"
}
})
@Html.ValidationMessageFor(model => model.LName, "", new {
@class = "text-danger"
}) <
/div> <
/div> <
div class = "form-group" >
@Html.LabelFor(model => model.Password, htmlAttributes: new {
@class = "control-label col-md-2"
}) <
div class = "col-md-10" >
@Html.EditorFor(model => model.Password, new {
htmlAttributes = new {
@class = "form-control"
}
})
@Html.ValidationMessageFor(model => model.Password, "", new {
@class = "text-danger"
}) <
/div> <
/div> <
div class = "form-group" >
@Html.LabelFor(model => model.City, htmlAttributes: new {
@class = "control-label col-md-2"
}) <
div class = "col-md-10" >
@Html.EditorFor(model => model.City, new {
htmlAttributes = new {
@class = "form-control"
}
})
@Html.ValidationMessageFor(model => model.City, "", new {
@class = "text-danger"
}) <
/div> <
/div>
<
div class = "form-group" >
<
div class = "col-md-offset-2 col-md-10" >
<
input type = "submit"
value = "Create"
class = "btn btn-default" / >
<
/div> <
/div> <
/div>
}
<
/body> <
/html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Registration.Models;
namespace Registration.Controllers {
public class HomeController: Controller {
public ActionResult Index() {
return View();
}
[HttpPost]
public ActionResult Index(tblRegistration obj)
{
if (ModelState.IsValid) {
RegMVCEntities db = new RegMVCEntities();
db.tblRegistrations.Add(obj);
db.SaveChanges();
}
return View(obj);
}
}
}
Comments
Leave a comment