Search panel in Asp.net MVC Application helps you to sort the data...
Introduction
In this Article Iam introducing how to work with search panel in MVC5..before we begin please have a look at my previous articles on
Working with Models and connection string in MVC5 Using Visual studio 2013 RC and
Lets start inserting some data in the database using front end as shown below...Debug the Application and insert some data
Lets look how to search the records by name Using the code
Open the StudentsController class file and replace the index Method code with the snippet given below
Here I have used LINQ Query which will select the name of the Students
public ActionResult Index(string SearchName)
{
var Students = from st in db.Students select st;
if (!String.IsNullOrEmpty(SearchName))
{
Students = Students.Where(c => c.studentname.Contains(SearchName));
}
return View(Students);
}
Now Change the view with search Panel
Navigate to Views Folder go to Students view and click on index.cshtml and create the textbox and search button as shown
<p>
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm())
{
<p>
Name: @Html.TextBox("SearchName")<br />
<input type="submit" value="Search" />
</p>
Now debug the Application and u will fine the Search Panel as shown below
Now search with some Student name u will get the Results as shown
Conclusion
This article will help to create a Search Panel in User Interface Layer in MVC5 application. Here we have created an action method and a view that will search Students by name.. So please go through my previous articles to better understand this.
Reference
http://msdn.microsoft.com/en-us/library/ee256141(v=vs.100).aspx