Here I have created sample using aspx engine,you can implement same using razor
Employee.aspx(View)
<div>
<h2>
Employee</h2>
<% using (Html.BeginForm("Employee", "Home", FormMethod.Post))
{ %>
Country:
<input type="text" id="country" name="country" />
<input type="submit" value="Get Data by country" />
<br />
Department :<input type="text" id="department" name="department" />
<input type="submit" value="Get Data by department" />
<br />
<br />
<table border="1">
<tr>
<th>
Name
</th>
<th>
Email
</th>
<th>
Contact
</th>
<th>
Country
</th>
<th>
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>
<%} %>
</div>
HomeController(Controller)
[HttpGet]
[ActionName("Employee")]
public ActionResult EmployeeData()
{
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"}
};
return View(emp);
}
[HttpPost]
[ActionName("Employee")]
public ActionResult EmployeeData(string country, string department)
{
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"}
};
if (!string.IsNullOrEmpty(country) && string.IsNullOrEmpty(department))
{
return View(emp.Where(x => x.Country == country.Trim()));
}
else if (!string.IsNullOrEmpty(department) && string.IsNullOrEmpty(country))
{
var empByDepts = emp.Where(x => x.Department == department.Trim());
return View(empByDepts);
}
else if (!string.IsNullOrEmpty(department) && !string.IsNullOrEmpty(country))
{
return View(emp.Where(x => (x.Country == country.Trim()) && (x.Department == department.Trim())));
}
else
{
return View(emp);
}
}
Employee.cs(Model)
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; }
}
Screenshot