using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using CrudExample.Models;
namespace CrudExample.Controllers
public class StudentsController : Controller
private StudentRecord db = newStudentRecord();
public ActionResult Index()
return View(db.Students.ToList());
public ActionResult Details(int? id)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
Student student = db.Students.Find(id);
public ActionResult Create()
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,Name,Email,Contact")] Student student)
db.Students.Add(student);
return RedirectToAction("Index");
public ActionResult Edit(int? id)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
Student student = db.Students.Find(id);
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "ID,Name,Email,Contact")] Student student)
db.Entry(student).State = EntityState.Modified;
return RedirectToAction("Index");
public ActionResult Delete(int? id)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
Student student = db.Students.Find(id);
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
Student student = db.Students.Find(id);
db.Students.Remove(student);
return RedirectToAction("Index");
protected override void Dispose(bool disposing)