Rahul Patil

Rahul Patil

  • 1.5k
  • 183
  • 31.1k

How to access a view in layout.cshtml in mvc??

Dec 23 2019 7:08 AM
I m working with MVC I m newbie in mvc.
 
when I m accessing an individual view then give an error: Additional information: Section not defined: "ContactUs". 
 
 HomeController:
  1.   public class HomeController : Controller  
  2.     {  
  3.         // GET: Home  
  4.         public ActionResult Index()  //main content  
  5.         {  
  6.             return View();  
  7.         }  
  8.   
  9.         public ActionResult ContactUs()  
  10.         {  
  11.             return View();  
  12.         }  
  13.   
  14.     }  
  15.   
 Index.cshtml
 
  1. @{  
  2.     ViewBag.Title = "Index";  
  3. }  
  4. Index

      
  5. This is main body means Dynamic Content  
layout.cshtml
 
  1.   
  2.   
  3.   
  4.     "utf-8" />  
  5.     "viewport" content="width=device-width, initial-scale=1.0">  
  6.     @ViewBag.Title - Template Editing  
  7.     "~/Content/Site.css" rel="stylesheet" type="text/css" />  
  8.     "~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />  
  9.     <!-- Inject Script Filtered -->  
  10.   
  11.   
  12.     class="container body-content">  
  13.         
      
  14.             

    Good Template

      
  15.           
  16.         @RenderBody()  
  17.         @RenderSection("ContactUs")   //here get an error Additional information: Section not defined: "ContactUs".
  18.         
      
  19.             

    2016@CopyRightsReserved

      
  20.           
  21.     
  
  •   
  •     <!-- Inject Script Filtered -->  
  •     <!-- Inject Script Filtered -->  
  •   
  •   
  •  ContactUs.cshtml
     
    1. @{  
    2.     ViewBag.Title = "ContactUs";  
    3. }  
    4.   
    5. ContactUs

        
    6.   
    7. hello this is good guy Contact This Person

         
    when I m accessing a contact.cshtml then error shown section is not defined?? 

    Answers (4)