I want multiple filter in same view
with multiple button
Employee Model class
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string contact { get; set; }
public string Country { get; set; }
public string Department { get; set; }
}
Controller Home
#region "Employee Objects data"
IEnumerable<Employee> emp = new List<Employee>()
{
new Employee(){ID=1,Name="David",Email="david@hr.com",contact="56142582376",Country="New Zealand" ,Department="HR"},
new Employee(){ID=2,Name="Jhon",Email="Jhon@it.com",contact="8934758934",Country="Sweden",Department="IT"},
new Employee(){ID=3,Name="Natsha",Email="Natsha@hr.com",contact="2386784356",Country="United Kingdom",Department="HR"},
new Employee(){ID=4,Name="Maria",Email="Maria@it.co.uk",contact="1248902357",Country="United Kingdom",Department="IT"},
new Employee(){ID=5,Name="james",Email="james@acc.com",contact="325783589",Country="America",Department="ACC"},
new Employee(){ID=6,Name="Paul",Email="Paul@it.com",contact="95804693476",Country="South Africa",Department="IT"},
new Employee(){ID=7,Name="Desiel",Email="Desiel@hr.com",contact="0085947587258",Country="Russia",Department="HR"},
new Employee(){ID=8,Name="Ronald",Email="Ronald@acc.com",contact="89756237523",Country="Germany",Department="ACC"},
new Employee(){ID=9,Name="Thomas",Email="Thomas@acc.com",contact="889456785665",Country="France",Department="ACC"},
new Employee(){ID=10,Name="Ryan",Email="Ryan@it.com",contact="2467846786376",Country="America",Department="IT"},
new Employee(){ID=11,Name="Dave",Email="Dave@hr.com",contact="3578934758965",Country="Germany",Department="HR"},
new Employee(){ID=12,Name="Sara",Email="Sara@ac.com",contact="4578975823",Country="Poland",Department="ACC"},
new Employee(){ID=13,Name="Dayna",Email="Dayna@it.com",contact="76578237865",Country="Australia",Department="IT"}
};
#endregion
#region "Get Employee View"
[HttpGet]
[ActionName("Employee")]
public ActionResult EmployeeData()
{
IEnumerable<Employee> data= emp.ToList();
return View(data);
}
#endregion
#region "Employee's filter by Country"
[HttpPost]
[ActionName("Employee")]
public ActionResult EmployeeAllData(string country)
{
IEnumerable<Employee> data = emp.Where(x => x.Country == country).ToList();
return View(data);
}
#endregion
#region "Employee's filtered by department"
[HttpPost]
[ActionName("Employee")]
public ActionResult EmployeeDepartment(string department)
{
IEnumerable<Employee> data = emp.Where(x => x.Department == department).ToList();
return View(data);
}
#endregion
Employee Cshtml
@model IEnumerable<AjaxDemo.Models.Employee>
@{
ViewBag.Title = "Employee";
}
<h2>Employee</h2>
@using (Html.BeginForm("Employee", "Home", FormMethod.Post))
{
<input type="text" id="country" name="country" /><input type="submit" value="GetData by country" />
}
@using (Html.BeginForm("Employee", "Home", FormMethod.Post))
{
<input type="text" id="department" name="department" /><input type="submit" value="Getdata by Department" />
}
<table border="1" >
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.contact)
</th>
<th>
@Html.DisplayNameFor(model => model.Country)
</th>
<th>
@Html.DisplayNameFor(model => model.Department)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.contact)
</td>
<td>
@Html.DisplayFor(modelItem => item.Country)
</td>
<td>
@Html.DisplayFor(modelItem => item.Department)
</td>
</tr>
}
</table>