Akash Patel

Akash Patel

  • 1.7k
  • 114
  • 8.8k

Bind respective record detail to modal in asp.net core

Jan 26 2019 10:30 PM
I am working on a project in which there is a partial view. in that i m using razor syntax for displaying div in which records will be displayed using foreach loop. In each div there is a view more link and when clicked it displays description in modal popup. But the problem is that when view more link is clicked of any record the description of only first record is displayed rather than displaying respective records description. Please help me out.
 
Code
 
  1. @using NiyaSpa.Models  
  2. @model Tuple<Booking, Customer>  
  3. <div class="inner-agile-w3l-part-head">  
  4. <h2 class="w3l-inner-h-title">Facials</h2>  
  5. </div>  
  6. <div>  
  7. <p style="text-align:center; font-size:medium;">  
  8. We provide skin specific facials as listed below. Each contains 5-8 step treatments including cleansing, chemical or physical exfoliation, gel treatment, steam facial, toning and moisturizing. Our blood circulating facial massage allows products to absorb deep into the skin giving clients long lasting results.  
  9. </p>  
  10. </div>  
  11. <br />  
  12. <br />  
  13. <div class="row">  
  14. <div class="card-deck">  
  15. @{  
  16. foreach (var facialService in ViewBag.subServices as IEnumerable<SubService>)  
  17. {  
  18. int id = facialService.SubService_ID;  
  19. <div class="col-md-4" style="margin-bottom:25px;">  
  20. <div class="card border-primary mb-3" style="width: 18rem;">  
  21. <img style="width:280px; height:180px; border-radius:10px; border-width:thin;" class="card-img-top" src="~/images/t2.jpg" alt="Card image cap">  
  22. <div class="card-body">  
  23. <h4 class="card-title" style="font-weight:600; margin-bottom:10px; margin-top:10px">  
  24. @facialService.Sub_ServiceName  
  25. </h4>  
  26. <p class="card-text" style="margin:0 0 10px; font-size:small;">  
  27. @facialService.Description.Substring(0, 100)  
  28. <a href="modal" data-toggle="modal" data-target="#ModalDescription">View More...</a>  
  29. </p>  
  30. <a asp-controller="OurServices" asp-action="BookAppointment" data-toggle="modal" data-target="#ModalBooking" class="btn btn-primary">Book Now</a>  
  31. </div>  
  32. </div>  
  33. </div>  
  34. <!-- Modal Description -->  
  35. <div class="modal fade" id="ModalDescription" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">  
  36. <div class="modal-dialog modal-dialog-centered" role="document">  
  37. <div class="modal-content">  
  38. <div class="modal-header">  
  39. <h5 class="modal-title" id="exampleModalLongTitle" style="font-weight:600; font-size:18px">  
  40. @facialService.Sub_ServiceName  
  41. </h5>  
  42. <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size:22px; margin-top:-23px;">  
  43. <span aria-hidden="true">×</span>  
  44. </button>  
  45. </div>  
  46. <div class="modal-body" style="font-size:15px; padding:10px 15px; text-align:justify;">  
  47. <p> @facialService.Description</p>  
  48. </div>  
  49. <div class="modal-footer">  
  50. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>  
  51. </div>  
  52. </div>  
  53. </div>  
  54. </div>  
  55. }  
  56. }  
  57. </div>  
  58. </div>  
  59. <div class="modal fade" id="ModalBooking" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">  
  60. <div class="modal-dialog modal-dialog-centered" role="document">  
  61. <div class="modal-content">  
  62. <div class="modal-header">  
  63. <h5 class="modal-title" id="exampleModalLongTitle" style="font-weight:600; color:crimson; font-family:cursive; font-size:28px; text-align:center;">Book an Appointment</h5>  
  64. <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size:22px; margin-top:-28px;">  
  65. <span aria-hidden="true">×</span>  
  66. </button>  
  67. <div style="margin-top:10px;">  
  68. <p>  
  69. <label style="color:crimson; font-size:small;"><b>Booking Policies</b></label>  
  70. <ul style="font-size:11px; margin-top:2px;">  
  71. <li>  
  72. Please arrive 15 mins before your appointment.  
  73. </li>  
  74. <li>  
  75. For appointment cancellation, please call 24 hours before.  
  76. </li>  
  77. <li>  
  78. To make your experience more enjoyable please turn off your phone during body massages and facial.  
  79. </li>  
  80. </ul>  
  81. </p>  
  82. </div>  
  83. </div>  
  84. <div class="modal-body" style="font-size:15px; padding:15px 15px; text-align:justify; margin-top:-15px">  
  85. <div class="signup-form">  
  86. <form asp-controller="OurServices" asp-action="BookAppointment" method="post">  
  87. <div class="form-group">  
  88. <div class="input-group">  
  89. <span class="input-group-addon"><i class="fa fa-user"></i></span>  
  90. <input type="text" asp-for="Item2.CustomerName" placeholder="Customer Name" class="form-control" required="required" />  
  91. </div>  
  92. </div>  
  93. <div class="form-group">  
  94. <div class="input-group">  
  95. <span class="input-group-addon"><i class="fa fa-paper-plane"></i></span>  
  96. <input type="email" asp-for="Item2.Email_ID" placeholder="Email Address" class="form-control" required="required" />  
  97. </div>  
  98. </div>  
  99. <div class="form-group">  
  100. <div class="input-group">  
  101. <span class="input-group-addon"><i class="fa fa-phone"></i></span>  
  102. <input type="text" asp-for="Item2.PhoneNumber" placeholder="Contact Number" class="form-control" required="required" />  
  103. </div>  
  104. </div>  
  105. <div class="form-group">  
  106. <div class="input-group date">  
  107. <div class="input-group-addon">  
  108. <i class="fa fa-calendar"></i>  
  109. </div>  
  110. <input type="text" class="form-control pull-right" asp-for="Item1.BookingDate" placeholder="Appointment Date" required="required" id="datepicker">  
  111. </div>  
  112. <!-- /.input group -->  
  113. </div>  
  114. <div class="form-group">  
  115. <div class="input-group">  
  116. <span class="input-group-addon"><i class="fa fa-list"></i></span>  
  117. <input type="text" asp-for="Item1.SubService.ServiceName" class="form-control" placeholder="Service Name" disabled="disabled" />  
  118. </div>  
  119. </div>  
  120. <div class="form-group">  
  121. <div class="input-group">  
  122. <span class="input-group-addon"><i class="fa fa-dollar"></i></span>  
  123. <input type="text" asp-for="Item1.TotalAmount" class="form-control" placeholder="Total Amount" disabled="disabled" />  
  124. </div>  
  125. </div>  
  126. <br />  
  127. <div class="form-group">  
  128. <button type="submit" class="btn btn-primary btn-block btn-lg" style="background-color:crimson; border-color:crimson;">Book Appointment</button>  
  129. </div>  
  130. </form>  
  131. </div>  
  132. </div>  
  133. </div>  
  134. @*<div class="modal-footer">  
  135. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>  
  136. </div>*@  
  137. </div>  
  138. </div>