Now, I will show you how we can add searching functionality into our application. You have to read Details and User Picture in MVC 5 before starting. We will simply add a search box into our index page of <Views\User\Index> folder, so that we can be able to search for a specific person. Then, we will try to customize the way we see our user details page.
Searching
Searching
- Download the source code from the above link and use it.
- Go to the Controllers folder and find UsersController.
- Replace the Index ActionResult with this piece of code.
Note that I am searching by location. You can search by other factors too.- public ActionResult Index(string searchString)
- {
- var users = from u in db.Users
- select u;
- if (!String.IsNullOrEmpty(searchString))
- {
- users = users.Where(s => s.Location.Contains(searchString));
- }
- return View(users);
- }
- Go to <Views\Users\Index> and add this code.Yeah! That's it. We have finished with the search. Here is the Result.
- @using (Html.BeginForm())
- {
- @Html.ActionLink("Create Profile", "Create", "Users")
- <p>
- Enter any location
- <div class="col-sm-3 col-md-3 pull-left">
- <div class="input-group">
- <input type="text" class="form-control" placeholder="Search" name="searchString">
- <div class="input-group-btn">
- <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
- </div>
- </div>
- </div>
- </p>
- }

Now, we are going to customize our details page. It looks like this now.
First, we have to add this piece of code to the details.chtml located in the <Views\Users\Details>. Next, we have to do something with CSS for animating.
Prasanna MuraliPosted Aug 22, 2016, 10:19 AM
Nice one....
Ramesh PalaniappanPosted Aug 22, 2016, 1:52 AM
Good One