namespace MvcDetail.Models
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class EmployeeDBContext : DbContext
{
public EmployeeDBContext()
: base("name=EmployeeDBContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<tblEmp> tblEmps { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcDetail.Models;
namespace MvcDetail.Controllers
{
public class HomeController : Controller
{
public ActionResult Details(int id)
{
EmployeeDBContext db = new EmployeeDBContext();
tblEmp emp=db.tblEmps.Single(x => x.EmpID == id);
return View(emp);
}
}
}
@model MvcDetail.Models.tblEmp
@{
ViewBag.Title = "Details";
}
<div style="font-family:Arial; font-size:medium; color:darkblue">
<h2>Employee Details</h2>
<fieldset>
<legend>tblEmp</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.EmpID)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.EmpID)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Name)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Name)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Gender)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Gender)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Salary)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Salary)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Address)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Address)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.DEPID)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.DEPID)
</div>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { /* id=Model.PrimaryKey */ }) |
@Html.ActionLink("Back to List", "Index")
</p>
</div>