title: _Layout.cshtml cannot be requested directly because it calls the "RenderBody" method
body: <p>I using attribute to routing. Is that relevant, I don't know.</p>
  
  <p>When I don't use "Route" attribute, _Layaout() action in shared controller doesn't work but page is rendering.</p>
  
  <pre><code>public class SharedController : Controller
      {
          // GET: Shared
          [AllowAnonymous]
          public ActionResult _Layout()
          {
  
              return View();
          }
      }
  </code></pre>
  
  <p>When I use "Route" attribute it does work but I getting following error:</p>
  
  <pre><code>public class SharedController : Controller
  {
      // GET: Shared
      [AllowAnonymous]
      [Route]
      public ActionResult _Layout()
      {
  
          return View();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>The file "~/Views/Shared/_Layout.cshtml" cannot be requested directly
    because it calls the "RenderBody" method.</p>
  </blockquote>
  
  <p>Also global.asax</p>
  
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                  "Default",                                              // Route name
                  "{controller}/{action}/",                           // URL with parameters
                  new { controller = "Home", action = "Index" }  // Parameter defaults
              );
          }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>_Layout.cshtml</p>
  
  <pre><code> @model OgrenciEvi.Models.ViewModel
  
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8" /&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
          &lt;title&gt;@ViewBag.Title - Ogrencievi.net&lt;/title&gt;
          &lt;link href="~/Content/Site.css" rel="stylesheet" type="text/css" /&gt;
          &lt;link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" /&gt;
          &lt;link href="~/Content/font-awesome.min.css" rel="stylesheet" /&gt;
          &lt;link href="~/Content/tether.css" rel="stylesheet" type="text/css" /&gt;
  
          &lt;link rel="icon" type="image/png" href="~/Image/favicon.ico" /&gt;
  
          &lt;script src="@Url.Content("~/Scripts/jquery-3.0.0.min.js")"&gt;&lt;/script&gt;
          &lt;script src="@Url.Content("~/Scripts/tether.js")"&gt;&lt;/script&gt;
          &lt;script src="@Url.Content("~/Scripts/bootstrap.min.js")"&gt;&lt;/script&gt;
          &lt;script src="http://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
          &lt;script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body class="p-0"&gt;
  
          @Html.Partial("Navbar")
          &lt;div class="container-fluid p-0"&gt;
              @RenderBody()
  
          &lt;/div&gt;
          @Html.Partial("_LoginModal",Model)
          @Html.Partial("_GoogleAnalyticTracker")
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Index.cshtml:</p>
  
  <pre><code>@model OgrenciEvi.Models.ViewModel
  
  @{
      Layout = "~/Views/Shared/_Layout.cshtml";
      ViewBag.Title = "Ana Sayfa";
  }
  
  @Html.Partial("LandingSection/SearchSection", Model)
  </code></pre>
  
  <p>_ViewStart.cshtml:</p>
  
  <pre><code>@{
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fj46L.png" rel="nofollow noreferrer">Path Image</a></p>