<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<style>
table, th, td
{
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd)
{
background-color: #ffe6e6;
}
table tr:nth-child(even)
{
background-color: #ccffcc;
}
</style>
</head>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<div>
<table>
<tr>
<td colspan="2" style="text-align:center"><h3>Employee Detail</h3></td>
</tr>
<tr>
<td style="width:130px">@Html.ActionLink("Employee List","Index")</td>
<td style="width:500px">@RenderBody()</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><h3>Website Footer</h3></td>
</tr>
</table>
</div>
</body>
</html>
using MvcLayoutDemo.Models;
using System.Data;
using System.Linq;
using System.Web.Mvc;
namespace MvcLayoutDemo.Controllers
{
public class HomeController : Controller
{
private EmployeeDBContext db = new EmployeeDBContext();
// GET: /Home/
public ActionResult Index()
{
return View(db.tblEmp.ToList());
}
// GET: /Home/Details/5
public ActionResult Details(int id = 0)
{
tblEmp tblemp = db.tblEmp.Find(id);
if (tblemp == null)
{
return HttpNotFound();
}
return View(tblemp);
}
// GET: /Home/Create
public ActionResult Create()
{
return View();
}
// POST: /Home/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(tblEmp tblemp)
{
if (ModelState.IsValid)
{
db.tblEmp.Add(tblemp);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(tblemp);
}
// GET: /Home/Edit/5
public ActionResult Edit(int id = 0)
{
tblEmp tblemp = db.tblEmp.Find(id);
if (tblemp == null)
{
return HttpNotFound();
}
return View(tblemp);
}
// POST: /Home/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(tblEmp tblemp)
{
if (ModelState.IsValid)
{
db.Entry(tblemp).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(tblemp);
}
// GET: /Home/Delete/5
public ActionResult Delete(int id = 0)
{
tblEmp tblemp = db.tblEmp.Find(id);
if (tblemp == null)
{
return HttpNotFound();
}
return View(tblemp);
}
// POST: /Home/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
tblEmp tblemp = db.tblEmp.Find(id);
db.tblEmp.Remove(tblemp);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
@{
ViewBag.Title = "Employee Detail";
Layout = "∼/Views/Shared/_Layout.cshtml";
}
@{
Layout = "∼/Views/Shared/_Layout.cshtml";
}