Registration Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using test_arth.Models;
namespace test_arth.Controllers
{
public class RegistrationController : Controller
{
// GET: Registration
dbEmployeeEntities context = new dbEmployeeEntities();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(RegistrationModel model1)
{
if (ModelState.IsValid)
{
tblRegistration obj = new tblRegistration();
obj.FirstName = model1.FirstName;
obj.LastName = model1.LastName;
obj.City = model1.City;
obj.State = model1.State;
obj.DOB = model1.DOB;
obj.TotalExperience = model1.TotalExperience;
obj.Salary = model1.Salary;
context.tblRegistrations.Add(obj);
context.SaveChanges();
}
return View(model1);
}
public ActionResult List()
{
var list = (from o in context.tblRegistrations
select new RegistrationModel
{
FirstName = o.FirstName,
LastName = o.LastName,
City = o.City,
State = o.State,
DOB = o.DOB,
TotalExperience = o.TotalExperience,
Salary = o.Salary
}).ToList() ;
return View(list);
}
[HttpPost]
public ActionResult List(string Searchstring)
{
var list = (from o in context.tblRegistrations
select new RegistrationModel
{
FirstName = o.FirstName,
LastName = o.LastName,
City = o.City,
State = o.State,
DOB = o.DOB,
TotalExperience = o.TotalExperience,
Salary = o.Salary
}).ToList();
if (!string.IsNullOrEmpty(Searchstring))
{
list = list.Where(x => x.TotalExperience.ToString().Contains(Searchstring)|| x.Salary.ToString().Contains(Searchstring)).ToList();
}
return View(list);
}
}
}
==========================================
Registration Model
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace test_arth.Models
{
public class RegistrationModel
{
public int Id { get; set; }
[Required(ErrorMessage = "Please enter firstname")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Please enter lastname")]
public string LastName { get; set; }
[Required(ErrorMessage = "Please enter city")]
public string City { get; set; }
[Required(ErrorMessage = "Please enter state")]
public string State { get; set; }
[Required(ErrorMessage = "Please enter DOB")]
public DateTime DOB { get; set; }
[Required(ErrorMessage = "Please enter Total Experience")]
public int TotalExperience { get; set; }
[Required(ErrorMessage = "Please enter salary")]
public decimal Salary { get; set; }
}
}
=============================================
Registration Index
@using test_arth.Models
@model RegistrationModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<html>
<head></head>
<body>
<div class="container">
<div class="col-md-12">
@using(Html.BeginForm("Index","Registration",FormMethod.Post))
{
<div class="row">
<div class="col-md-12">
@Html.TextBoxFor(x => x.FirstName, new { @placeholder = "Enter firstname" })
@Html.ValidationMessageFor(x => x.FirstName)
</div>
<div class="col-md-12">
@Html.TextBoxFor(x => x.LastName, new { @placeholder = "Enter lastname" })
@Html.ValidationMessageFor(x => x.LastName)
</div>
<div class="col-md-12">
@Html.TextBoxFor(x => x.City, new { @placeholder = "Enter city" })
@Html.ValidationMessageFor(x => x.City)
</div>
<div class="col-md-12">
@Html.TextBoxFor(x => x.State, new { @placeholder = "Enter state" })
@Html.ValidationMessageFor(x => x.State)
</div>
<div class="col-md-12">
@Html.TextBoxFor(x => x.DOB, new { @Type = "date", @placeholder = "Enter DOB" })
@Html.ValidationMessageFor(x => x.Salary)
</div>
<div class="col-md-12">
@Html.TextBoxFor(x => x.TotalExperience, new { @placeholder = "Enter TotalExperience" })
@Html.ValidationMessageFor(x => x.Salary)
</div>
<div class="col-md-12">
@Html.TextBoxFor(x => x.Salary, new { @placeholder = "Enter salary" })
@Html.ValidationMessageFor(x => x.Salary)
</div>
<div class="col-md-12">
<button type="submit" id="button1">Submit</button>
<a href="/login">Login</a>
</div>
</div>
}
</div>
</div>
</body>
</html>