Skip to content
Loading
How to access a view in layout.cshtml in mvc??
0
  • Rajeesh Menoth
    Hi Rahul, "RenderSection(string sectionName, bool required):" Please read the article : https://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor
    0
  • @Rajeesh Menoth when I m creating another individual view for ex: header then again give an error

     
    layout.cshtml
     
    1.   
    2.     class="container body-content">  
    3.         @RenderSection("Header")   //Section not defined: "Header".
    4.         @RenderBody()  
    5.         @RenderSection("ContactUs")  
    6.         
        
    7.             

      2016@CopyRightsReserved

        
    8.           
    9.     
      
  •   
  •     "~/Scripts/jquery-1.10.2.min.js">  
  •     "~/Scripts/bootstrap.min.js">  
  •   
  • HomeController:
    1.         public ActionResult ContactUs()  
    2.         {  
    3.             return View();  
    4.         }  
    5.   
    6.         public ActionResult Header()  
    7.         {  
    8.             return View();  
    9.         }  
     Headr.cshtml
     
    1. @{  
    2.     ViewBag.Title = "Header";  
    3. }  
    4.   
    5. Header

        
    6.   
    7. @section Header{  
    8.     

      hello Header

        
    9. }  
    10.    

     

    0
  • Rajeesh Menoth
    Hi,
     
    Please check the following reference :
     
    https://stackoverflow.com/questions/10971149/the-following-sections-have-been-defined-but-have-not-been-rendered-for-the-layo
     
    https://www.techcartnow.com/conditionally-render-sections-asp-net-mvc/
     
    https://www.c-sharpcorner.com/UploadFile/3d39b4/Asp-Net-mvc-4-layout-and-section-in-razor/ 
    0