Hi chetan,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Model
public class EmployeeModel
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string CheckIn { get; set; }
public string CheckOut { get; set; }
public DateTime Date { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Submit()
{
List<EmployeeModel> employees = new List<EmployeeModel>();
employees.AddRange(new EmployeeModel[] {
new EmployeeModel { EmployeeId = 1, Name = "NancyDavolio", CheckIn = "08:00", CheckOut = "17:10", Date = DateTime.Now },
new EmployeeModel { EmployeeId = 2, Name = "AndrewFuller", CheckIn = "08:05", CheckOut = "17:00", Date = DateTime.Now },
new EmployeeModel { EmployeeId = 3, Name = "JanetLeverling", CheckIn = "08:15", CheckOut = "17:25", Date = DateTime.Now },
new EmployeeModel { EmployeeId = 4, Name = "MargaretPeacock", CheckIn = "08:02", CheckOut = "14:30", Date = DateTime.Now },
new EmployeeModel { EmployeeId = 5, Name = "StevenBuchanan", CheckIn = "08:13", CheckOut = "17:30", Date = DateTime.Now }
});
return View("Index", employees);
}
}
View
@model IEnumerable<Show_Table_Button_MVC.Models.EmployeeModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@using (Html.BeginForm("Submit", "Home", FormMethod.Post))
{
<input type="submit" value="Submit" />
}
@if (Model != null)
{
<hr />
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Check In</th>
<th>Check Out</th>
<th>Date</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.EmployeeId</td>
<td>@item.Name</td>
<td>@item.CheckIn</td>
<td>@item.CheckOut</td>
<td>@item.Date.ToShortDateString()</td>
</tr>
}
</table>
}
</body>
</html>
Screenshot