Hi 65sametkaya65,
Refer below example.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
NorthwindEntities entities = new NorthwindEntities();
return View(entities.Employees.ToList());
}
[HttpPost]
public ActionResult Index(string fromDate, string toDate)
{
NorthwindEntities entities = new NorthwindEntities();
List<Employee> employees = entities.Employees.ToList();
if (!string.IsNullOrEmpty(fromDate) && !string.IsNullOrEmpty(toDate))
{
DateTime startDate = Convert.ToDateTime(fromDate);
DateTime endDate = Convert.ToDateTime(toDate);
employees = employees.Where(x => x.BirthDate >= startDate && x.BirthDate <= endDate).ToList();
}
return View(employees);
}
}
View
@model IEnumerable<Sample_156648.Employee>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
table { border: 1px solid #ccc; border-collapse: collapse; }
table th { background-color: #F7F7F7; color: #333; font-weight: bold; }
table th, table td { padding: 5px; border: 1px solid #ccc; }
table, table table td { border: 0px solid #ccc; }
</style>
</head>
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<input type="text" name="fromDate" /><br />
<input type="text" name="toDate" /><br />
<input type="submit" value="Search" />
}
@if (Model != null)
{
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.BirthDate)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.BirthDate)
</td>
</tr>
}
</table>
}
</body>
</html>
Screenshot