Skip to content
Loading
Getting error on using partial view in asp.net core 2.2  
  •   
  • class="gallery-grids">  
  • @foreach (var services in Model)  
  • {  
  • class="col-md-4 gallery-grid">  
  • class="grid">  
  • class="effect-apollo">  
  • class="example-image-link" asp-controller="OurServices" asp-action="SingleView" asp-route-serviceId="@Convert.ToInt32(services.Service_ID)" data-lightbox="example-set" >  
  • "~/images/g8.jpg" alt="" />  
  •   
  • @services.ServiceName

      
  •   
  •   
  •   
  •   
  •   
  • }  
  • class="clearfix">   
  •   
  •   
  •   
  •   
  • Our Services Controller:
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Threading.Tasks;  
    5. using Microsoft.AspNetCore.Mvc;  
    6. using NiyaSpa.Models;  
    7. namespace NiyaSpa.Controllers  
    8. {  
    9. public class OurServicesController : Controller  
    10. {  
    11. private NiyaDBContext _dbcontext=null ;  
    12. public OurServicesController(NiyaDBContext dbContext)  
    13. {  
    14. _dbcontext = dbContext;  
    15. }  
    16. public IActionResult OurServices()  
    17. {  
    18. return View(_dbcontext.Services.ToList());  
    19. }  
    20. public IActionResult SingleView(int ServiceId)  
    21. {  
    22. var serviceName = _dbcontext.Services.SingleOrDefault(s => s.Service_ID == ServiceId)?.ServiceName;  
    23. ViewBag.service_name = serviceName;  
    24. return View();  
    25. }  
    26. }  
    27. }  
    Single View Code
    1. @model NiyaSpa.Models.Booking  
    2. @{  
    3. ViewData["Title"] = "SingleView";  
    4. Layout = "~/Views/Shared/_NiyaSpaLayout.cshtml";  
    5. }  
    6. @{  
    7. var sname = ViewBag.service_name;  
    8. }  
    9. class="w3_breadcrumb">  
    10. class="breadcrumb-inner">  
      •   
      • "">Our Services  /
      •   
      • @sname
      •   
        
      
  •   
  • class="w3_content_agilleinfo_inner">  
  • class="container">  
  • @{  
  • await Html.PartialAsync("_Facials"new Booking());  
  • }  
  •   
  •   
  • _Facial - Partial View Code
    1. @model NiyaSpa.Models.Booking  
    2. class="inner-agile-w3l-part-head">  
    3. class="w3l-inner-h-title">Facials  
      
  •   
  • "text-align:center; font-size:medium;">  
  • 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.  
  •   
  •   
  •   
  •   
  • class="row">  
  • class="card-deck">  
  • @foreach (var facialService in Model as IEnumerable)  
  • {  
  • class="col-md-4">  
  • class="card border-primary mb-3" style="width: 18rem;">  
  • "width:280px; height:180px; border-radius:10px; border-width:thin;" class="card-img-top" src="~/images/t2.jpg" alt="Card image cap">  
  • class="card-body">  
  • class="card-title" style="font-weight:600; margin-bottom:10px; margin-top:10px">@facialService.SubService.ServiceName   
  • class="card-text" style="margin:0 0 10px; font-size:small;">  
  • @facialService.SubService.Description.Substring(0, 100);  
  • "modal" data-toggle="modal" data-target="#ModalDescription">View More...  
  •   
  • "OurServices" asp-action="BookAppointment" data-toggle="modal" data-target="#ModalBooking" class="btn btn-primary">Book Now  
  •   
  •   
  •   
  •   
  • class="modal fade" id="ModalDescription" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">  
  • class="modal-dialog modal-dialog-centered" role="document">  
  • class="modal-content">  
  • class="modal-header">  
  • class="modal-title" id="exampleModalLongTitle" style="font-weight:600; font-size:18px">@facialService.SubService.ServiceName   
  • "button" class="close" data-dismiss="modal" aria-label="Close" style="font-size:22px; margin-top:-23px;">  
  • "true"  
  •   
  •   
  • class="modal-body" style="font-size:15px; padding:10px 15px; text-align:justify;">  
  • @facialService.SubService.Description.Split("", StringSplitOptions.None) @facialService.SubService.Description  
  •   
  • class="modal-footer">  
  • "button" class="btn btn-secondary" data-dismiss="modal">Close  
  •   
  •   
  •   
  •   
  • }  
  •   
  •   
  • class="modal fade" id="ModalBooking" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">  
  • class="modal-dialog modal-dialog-centered" role="document">  
  • class="modal-content">  
  • class="modal-header">  
  • class="modal-title" id="exampleModalLongTitle" style="font-weight:600; color:crimson; font-family:cursive; font-size:28px; text-align:center;">Book an Appointment  
  • "button" class="close" data-dismiss="modal" aria-label="Close" style="font-size:22px; margin-top:-28px;">  
  • "true"  
  •   
  • "margin-top:10px;">  
  •   

  • "color:crimson; font-size:small;">Booking Policies  
  • "font-size:11px; margin-top:2px;">  
  •   
  • Please arrive 15 mins before your appointment.  
  •   
  •   
  • For appointment cancellation, please call 24 hours before.  
  •   
  •   
  • To make your experience more enjoyable please turn off your phone during body massages and facial.  
  •   
  •   
  •   
  •   
  •   
  • class="modal-body" style="font-size:15px; padding:15px 15px; text-align:justify; margin-top:-15px">  
  • class="signup-form">  
  • "OurServices" asp-action="BookAppointment" method="post">  
  • class="form-group">  
  • class="input-group">  
  • class="input-group-addon">class="fa fa-user">  
  • "text" asp-for="Customer.CustomerName" placeholder="Customer Name" class="form-control" required="required" />  
  •   
  •   
  • class="form-group">  
  • class="input-group">  
  • class="input-group-addon">class="fa fa-paper-plane">  
  • "email" asp-for="Customer.Email_ID" placeholder="Email Address" class="form-control" required="required" />  
  •   
  •   
  • class="form-group">  
  • class="input-group">  
  • class="input-group-addon">class="fa fa-phone">  
  • "text" asp-for="Customer.PhoneNumber" placeholder="Contact Number" class="form-control" required="required" />  
  •   
  •   
  • class="form-group">  
  • class="input-group date">  
  • class="input-group-addon">  
  • class="fa fa-calendar">  
  •   
  • "text" class="form-control pull-right" asp-for="BookingDate" placeholder="Appointment Date" required="required" id="datepicker">  
  •   
  •   
  •   
  • class="form-group">  
  • class="input-group">  
  • class="input-group-addon">class="fa fa-list">  
  • "text" asp-for="SubService.ServiceName" class="form-control" placeholder="Service Name" disabled="disabled" />  
  •   
  •   
  • class="form-group">  
  • class="input-group">  
  • class="input-group-addon">class="fa fa-dollar">  
  • "text" asp-for="TotalAmount" class="form-control" placeholder="Total Amount" disabled="disabled" />  
  •   
  •   
  •   
  • class="form-group">  
  • "submit" class="btn btn-primary btn-block btn-lg" style="background-color:crimson; border-color:crimson;">Book Appointment  
  •   
  •   
  •   
  •   
  •   
  • @*class="modal-footer">  
  • "button" class="btn btn-secondary" data-dismiss="modal">Close  
  • *@  
  •   
  •   
  • I am invoking partial view using @await Html.PartialAysnc("viewname","model");

    6 Replies

    Know the answer? Post it — somebody with the same question will find it here.