Adding Search And Customizing Details View

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
  1. Download the source code from the above link and use it.
  2. Go to the Controllers folder and find UsersController.
  3. Replace the Index ActionResult with this piece of code. 

    Note that I am searching by location. You can search by other factors too.
    1. public ActionResult Index(string searchString)    
    2.         {    
    3.               
    4.             var users = from u in db.Users    
    5.                          select u;    
    6.     
    7.             if (!String.IsNullOrEmpty(searchString))    
    8.             {    
    9.                 users = users.Where(s => s.Location.Contains(searchString));    
    10.             }    
    11.             
    12.             return View(users);    
    13.         }    
  4. Go to <Views\Users\Index> and add this code.
    1. @using (Html.BeginForm())    
    2.        {    
    3.            @Html.ActionLink("Create Profile""Create""Users")    
    4.            <p>    
    5.                Enter any location    
    6.                <div class="col-sm-3 col-md-3 pull-left">    
    7.                    <div class="input-group">    
    8.                        <input type="text" class="form-control" placeholder="Search" name="searchString">    
    9.                        <div class="input-group-btn">    
    10.                            <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>    
    11.                        </div>    
    12.                    </div>    
    13.                </div>    
    14.            </p>    
    15.        }   
     
    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.

 

F
irst, 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.
  1. @model CRUDwithPic.Models.User  
  2.   
  3. @{  
  4.     ViewBag.Title = "Details";  
  5. }  
  6. <h2>Details</h2>  
  7. <link rel="stylesheet" type="text/css" href="~/Content/Site.css" />  
  8. <div>  
  9.     <h4>User</h4>  
  10.     <hr />  
  11.     <div class="container">  
  12.         <div class="row">  
  13.             <div class="col-md-4">  
  14.                 <div class="form_hover" style="background-color:seagreen;  
  15.                     <p style=" text-align center; margin-top 20px;">  
  16.                     <i class="glyphicon glyphicon-ok-sign" style="font-size: 130px;"></i>  
  17.                     </p>  
  18.                     <div class="header" style="background-color:#cfcfcf;">  
  19.                         <div class="blur"></div>  
  20.                         <div class="header-text">  
  21.                             <div class="panel panel-success" style="background-color:seagreen;height:120px;width:400px;">  
  22.                                 <div class="panel-heading" style="background-color:gray;">  
  23.                                     <h4 style="color: #fff;">Complete Details <i class="glyphicon glyphicon-circle-arrow-up"></i></h4>  
  24.                                 </div>  
  25.                                 <div class="panel-body">  
  26.                                     <dl class="dl-horizontal">  
  27.   
  28.                                         @if (Model.Files.Any(f => f.FileType == CRUDwithPic.Models.FileType.Avatar))  
  29.                                         {  
  30.                                             <dt>  
  31.                                                 User Profile Picture  
  32.                                             </dt>  
  33.                                                 <dd>  
  34.                                                     <img src="~/File?id=@Model.Files.First(f => f.FileType == CRUDwithPic.Models.FileType.Avatar).FileId" alt="avatar" class="img-circle" height="100" width="100" />  
  35.                                                 </dd>  
  36.                                         }  
  37.                                         <dt>  
  38.                                             @Html.DisplayNameFor(model => model.Name)  
  39.                                         </dt>  
  40.   
  41.                                         <dd>  
  42.                                             @Html.DisplayFor(model => model.Name)  
  43.                                         </dd>  
  44.   
  45.                                         <dt>  
  46.                                             @Html.DisplayNameFor(model => model.LastName)  
  47.                                         </dt>  
  48.   
  49.                                         <dd>  
  50.                                             @Html.DisplayFor(model => model.LastName)  
  51.                                         </dd>  
  52.   
  53.                                         <dt>  
  54.                                             @Html.DisplayNameFor(model => model.Province)  
  55.                                         </dt>  
  56.   
  57.                                         <dd>  
  58.                                             @Html.DisplayFor(model => model.Province)  
  59.                                         </dd>  
  60.   
  61.                                         <dt>  
  62.                                             @Html.DisplayNameFor(model => model.District)  
  63.                                         </dt>  
  64.   
  65.                                         <dd>  
  66.                                             @Html.DisplayFor(model => model.District)  
  67.                                         </dd>  
  68.   
  69.                                         <dt>  
  70.                                             @Html.DisplayNameFor(model => model.Group)  
  71.                                         </dt>  
  72.   
  73.                                         <dd>  
  74.                                             @Html.DisplayFor(model => model.Group)  
  75.                                         </dd>  
  76.   
  77.                                         <dt>  
  78.                                             @Html.DisplayNameFor(model => model.RH)  
  79.                                         </dt>  
  80.   
  81.                                         <dd>  
  82.                                             @Html.DisplayFor(model => model.RH)  
  83.                                         </dd>  
  84.   
  85.                                         <dt>  
  86.                                             @Html.DisplayNameFor(model => model.Location)  
  87.                                         </dt>  
  88.   
  89.                                         <dd>  
  90.                                             @Html.DisplayFor(model => model.Location)  
  91.                                         </dd>  
  92.   
  93.                                         <dt>  
  94.                                             @Html.DisplayNameFor(model => model.Mobile)  
  95.                                         </dt>  
  96.   
  97.                                         <dd>  
  98.                                             @Html.DisplayFor(model => model.Mobile)  
  99.                                         </dd>  
  100.                                     </dl>  
  101.                                 </div>  
  102.                             </div>  
  103.                         </div>  
  104.                     </div>  
  105.                 </div>  
  106.             </div>  
  107.         </div>  
  108.     </div>  
  109. </div>  
  110. <br />   
  111. <p>  
  112.     @Html.ActionLink("Edit""Edit"new { id = Model.ID }) |  
  113.     @Html.ActionLink("Back to List""Index")  
  114. </p>   
Now, insert this to your site.css located at <content\site.css>.
  1. .form_hover {    
  2.         padding0px;    
  3.         positionrelative;    
  4.         overflowhidden;    
  5.         height360px;    
  6.     }    
  7.     
  8.         .form_hover:hover .header {    
  9.             opacity: 1;    
  10.             transform: translateY(-172px);    
  11.             -webkit-transform: translateY(-172px);    
  12.             -moz-transform: translateY(-172px);    
  13.             -ms-transform: translateY(-172px);    
  14.             -o-transform: translateY(-172px);    
  15.         }    
  16.     
  17.         .form_hover img {    
  18.             z-index4;    
  19.         }    
  20.     
  21.         .form_hover .header {    
  22.             positionabsolute;    
  23.             top: 170px;    
  24.             -webkit-transition: all 0.3s ease;    
  25.             -moz-transition: all 0.3s ease;    
  26.             -o-transition: all 0.3s ease;    
  27.             -ms-transition: all 0.3s ease;    
  28.             transition: all 0.3s ease;    
  29.             width100%;    
  30.         }    
  31.     
  32.         .form_hover .blur {    
  33.             height240px;    
  34.             z-index5;    
  35.             positionabsolute;    
  36.             width100%;    
  37.         }    
  38.     
  39.         .form_hover .caption-text {    
  40.             z-index10;    
  41.             color#fff;    
  42.             positionabsolute;    
  43.             height240px;    
  44.             text-aligncenter;    
  45.             top: -20px;    
  46.             width100%;    
  47.         }   
    Run your application now! Yes, we have successfully changed the details page. Stay tuned for the next article.