Here I am going to Show how to Retrieve Data from DataBase with the use of MVC
//inside the bracket () am writing the Model, Controller, View Names
Model Class(Emp_tb):-
public partial class Emp_tb
{
public int Id { get; set; }
public string Name { get; set; }
public Nullable<int> Age { get; set; }
public Nullable<System.DateTime> DOB { get; set; }
public string Sex { get; set; }
public string Address { get; set; }
public Nullable<bool> Active { get; set; }
}
Controller(NewEg):-
public ActionResult Index()
{
var list = db.Emp_tb.ToList();
return View(list);
}
View(Index);-
@model IEnumerable<final1.Models.Emp_tb>
@{
ViewBag.Title = "List";
}
<h2>List all the Values</h2>
@Html.ActionLink("Create New Employee", "Create", "NewEg")
<table class="table table-bordered">
<tr>
<th>
@Html.Label("Name")
</th>
<th>
@Html.Label("Age")
</th>
<th>
@Html.Label("DOB")
</th>
<th>
@Html.Label("Sex")
</th>
<th>
@Html.Label("Address")
</th>
</tr>
@foreach (var list in Model)
{
<tr>
<td>
@Html.DisplayFor(m => list.Name)
</td>
<td>
@Html.DisplayFor(m => list.Age)
</td>
<td>
@Html.DisplayFor(m => list.DOB)
</td>
<td>
@Html.DisplayFor(m => list.Sex)
</td>
<td>
@Html.DisplayFor(m => list.Address)
</td>
<td>
@Html.ActionLink("Edit", "Edit2", new { id = list.Id }) |
@Html.ActionLink("Details", "Details", new { id = list.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = list.Id })
</td>
</tr>
}
</table>
//inside the bracket () am writing the Model, Controller, View Names
Model Class(Emp_tb):-
public partial class Emp_tb
{
public int Id { get; set; }
public string Name { get; set; }
public Nullable<int> Age { get; set; }
public Nullable<System.DateTime> DOB { get; set; }
public string Sex { get; set; }
public string Address { get; set; }
public Nullable<bool> Active { get; set; }
}
Controller(NewEg):-
public ActionResult Index()
{
var list = db.Emp_tb.ToList();
return View(list);
}
View(Index);-
@model IEnumerable<final1.Models.Emp_tb>
@{
ViewBag.Title = "List";
}
<h2>List all the Values</h2>
@Html.ActionLink("Create New Employee", "Create", "NewEg")
<table class="table table-bordered">
<tr>
<th>
@Html.Label("Name")
</th>
<th>
@Html.Label("Age")
</th>
<th>
@Html.Label("DOB")
</th>
<th>
@Html.Label("Sex")
</th>
<th>
@Html.Label("Address")
</th>
</tr>
@foreach (var list in Model)
{
<tr>
<td>
@Html.DisplayFor(m => list.Name)
</td>
<td>
@Html.DisplayFor(m => list.Age)
</td>
<td>
@Html.DisplayFor(m => list.DOB)
</td>
<td>
@Html.DisplayFor(m => list.Sex)
</td>
<td>
@Html.DisplayFor(m => list.Address)
</td>
<td>
@Html.ActionLink("Edit", "Edit2", new { id = list.Id }) |
@Html.ActionLink("Details", "Details", new { id = list.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = list.Id })
</td>
</tr>
}
</table>
EmoticonEmoticon