Hii PRA.
Please refer below code.
Database
Here I am making use of Microsoft's Northwind Database. You can download it from here.
Download and install Northwind Database
View
@model Employee
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table>
<tr>
<td>
BirthDate
</td>
<td>
@Html.TextBoxFor(p => p.BirthDate)
</td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
}
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Birth Date</th>
</tr>
@foreach (var p in ViewBag.Employee)
{
<tr>
<td>@p.EmployeeID</td>
<td>@p.FirstName @p.LastName</td>
<td>@p.BirthDate.ToShortDateString()</td>
</tr>
}
</table>
</div>
</body>
</html>
Controller
public ActionResult Index()
{
ViewBag.Employee = GetEmployee("");
return View();
}
[HttpPost]
public ActionResult Index(Employee employee)
{
ViewBag.Employee = GetEmployee(employee.BirthDate.Value.ToShortDateString());
return View();
}
private static List<Employee> GetEmployee(string birthDate)
{
using (NORTHWINDEntities entities = new NORTHWINDEntities())
{
List<Employee> employees = (from p in entities.Employees
select p).ToList();
if (!string.IsNullOrEmpty(birthDate))
{
employees = employees.Where(x => x.BirthDate.Value.ToShortDateString() == birthDate).ToList();
}
return employees;
}
}
Screenshot