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
- 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.
- @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>
- }
Yeah! That's it. We have finished with the search. Here is the Result.
Customizing Details View
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.
Now, insert this to your site.css located at <content\site.css>.
- .form_hover {
- padding: 0px;
- position: relative;
- overflow: hidden;
- height: 360px;
- }
-
- .form_hover:hover .header {
- opacity: 1;
- transform: translateY(-172px);
- -webkit-transform: translateY(-172px);
- -moz-transform: translateY(-172px);
- -ms-transform: translateY(-172px);
- -o-transform: translateY(-172px);
- }
-
- .form_hover img {
- z-index: 4;
- }
-
- .form_hover .header {
- position: absolute;
- top: 170px;
- -webkit-transition: all 0.3s ease;
- -moz-transition: all 0.3s ease;
- -o-transition: all 0.3s ease;
- -ms-transition: all 0.3s ease;
- transition: all 0.3s ease;
- width: 100%;
- }
-
- .form_hover .blur {
- height: 240px;
- z-index: 5;
- position: absolute;
- width: 100%;
- }
-
- .form_hover .caption-text {
- z-index: 10;
- color: #fff;
- position: absolute;
- height: 240px;
- text-align: center;
- top: -20px;
- width: 100%;
- }
Run your application now! Yes, we have successfully changed the details page. Stay tuned for the next article.