Working With Search Panel in MVC5 Application Using Visual Studio 2013 RC

Rama Sagar
Posted by in ASP.NET MVC category on for Intermediate level | Points: 250 | Views : 3022 red flag

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 
Intoduction to Scaffolding in Visual Studio 2013 RC  as this article is the continuation part of them...



Objective


Adding  Search panel in Asp.net MVC5 Application...

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

Page copy protected against web site content infringement by Copyscape

About the Author

Rama Sagar
Full Name: RamaSagar Pulidindi
Member Level: Silver
Member Status: Member,MVP
Member Since: 12/30/2012 1:51:40 AM
Country: India
ramasagar
http://www.ramasagar.com
A Software Profesional working in Microsoft .NET technologies since year 2008, and I work for Dake ACE. I am passionate about .NET technology and love to contribute to the .NET community at Dot Net Funda

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)