In The Name of Allah!
CRUD Operation
Insertion
controller code
public ActionResult Index()
{
return View();
}
public ActionResult Create(Student obj)
{
[Link](obj);
[Link]();
return RedirectToAction("StudentList");
}
Insertion
View Code
<h2>Index</h2>
<form action="/Test/Create/" method="post">
<input type="text" name="Name" placeholder="Enter your name" class="form-
control" />
<input type="text" name="Fname" placeholder="Enter your father name"
class="form-control" />
<input type="text" name="Department" placeholder="Department Name"
class="form-control" />
<input type="submit" value="Submit" class="btn btn-primary" />
</form>
Reading Data
Controller Code
public ActionResult StudentList()
{
var obj = [Link];
return View(obj);
}
Reading
View Code
Editing
Controller Code
public ActionResult Edit(int id)
{
var obj = [Link](id);
return View(obj);
}
public ActionResult UpdateRecord(Student obj)
{
[Link](obj).State = [Link];
[Link]();
return RedirectToAction("StudentList");
}
Editing
View Code
@model [Link]
@{
[Link] = "Edit";
}
<h2>Edit</h2>
<form action="/Test/UpdateRecord/" method="post">
<input type="hidden" name="ID" value="@[Link]" class="form-control" />
<input type="text" name="Name" value="@[Link]" placeholder="Enter your name" class="form-control" />
<input type="text" name="Fname" value="@[Link]" placeholder="Enter your father name" class="form-control" />
<input type="text" name="Department" value="@[Link]" placeholder="Department Name" class="form-
control" />
<input type="submit" value="Update" class="btn btn-primary" />
</form>
Delete Code
public ActionResult Delete (int id){
var obj=[Link](id);
[Link](obj);
[Link]();
return RedirectToAction("StudentList");
}