---
title: "How to Filtering with the entity framework is an ASP.NET MVC Application"  
description: "How to Filtering with the entity framework is an ASP.NET MVC Application"  
author: "Anupam Mishra"  
published: 2016-02-05  
updated: 2016-02-05  
canonical: https://www.mindstick.com/forum/33958/how-to-filtering-with-the-entity-framework-is-an-asp-dot-net-mvc-application  
category: "asp.net"  
tags: ["c#", "asp.net", "asp.net mvc"]  
reading_time: 2 minutes  

---

# How to Filtering with the entity framework is an ASP.NET MVC Application

Hi Everyone,\
I want to know how to [Filter](https://www.mindstick.com/forum/1176/filter-in-a-xml-file-in-c-sharp) record with the using of [entity](https://www.mindstick.com/forum/160562/database-connectivity-using-entity-framework-database-first-approach) [framework in ASP.NET](https://www.mindstick.com/forum/158854/what-is-the-purpose-of-the-razor-pages-framework-in-asp-dot-net-core) MVC. Can [anyone give me](https://answers.mindstick.com/qa/41194/can-anyone-give-me-some-high-and-low-points-of-each-of-the-four-first-presidential-administrations) a solution.\
Thank you.

## Replies

### Reply by Anupam Mishra

Finally, I have resolve this problem.\
For Solution of above problem, we are creating one student controller and its index view. We want to display a Filter records(i.e. First Name,Last Name ) in index view. For this we create a search string text box in a view for searching FirstName,LastName in student records.\
this is a code of Student controller Index Action:

```
public ActionResult Index(string sortOrder, string searchString, string currentFilter){ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name" : "";ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date";ViewBag.CurrentFilter = searchString;if (!String.IsNullOrEmpty(searchString))
    {
        students = students.Where(s => s.FirstName.ToUpper().Contains(searchString.ToUpper())
                               || s.LastName.ToUpper().Contains(searchString.ToUpper()));
    }{        students = students.Where(s => s.FirstName.ToUpper().Contains(searchString.ToUpper())|| s.LastName.ToUpper().Contains(searchString.ToUpper()));}
   var students = from s in db.Student  // Student is a table i.e. containing records of studentselect s;switch (sortOrder){case "Name":         students = students.OrderByDescending(s => s.FirstName);break;case "Date":         students = students.OrderBy(s => s.EnrollmentDate);break;case "Date_desc":         students = students.OrderByDescending(s => s.EnrollmentDate);break;default:         students = students.OrderBy(s => s.FirstName);break;}return View(students.ToList());}
```

```
Now. we have changed the index view of student. Code is as Follows: 
```

```
  <h2>Student Index</h2>
    <p>
    @Html.ActionLink("Create New",  "Create")
    @using (Html.BeginForm("Index", "Student", FormMethod.Get))
     {
    <p>
        Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
        <input type="submit" value="Search" />
```


---

Original Source: https://www.mindstick.com/forum/33958/how-to-filtering-with-the-entity-framework-is-an-asp-dot-net-mvc-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
