属性をルーティングに使用しています。それは関連している、私は知らない。_Rayout.cshtmlは、「RenderBody」メソッドを呼び出すため直接リクエストできません
「ルート」属性を使用しない場合、共有コントローラの_Layaout()アクションは機能しませんが、ページがレンダリングされます。
public class SharedController : Controller
{
// GET: Shared
[AllowAnonymous]
public ActionResult _Layout()
{
return View();
}
}
私は "ルート" を使用し、それは作業を行い属性が、私は次のエラー取得:
:
public class SharedController : Controller
{
// GET: Shared
[AllowAnonymous]
[Route]
public ActionResult _Layout()
{
return View();
}
}
The file "~/Views/Shared/_Layout.cshtml" cannot be requested directly because it calls the "RenderBody" method.
も
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
);
}
編集をGlobal.asaxの_Layout.cshtml
@model OgrenciEvi.Models.ViewModel
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - Ogrencievi.net</title>
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/font-awesome.min.css" rel="stylesheet" />
<link href="~/Content/tether.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/png" href="~/Image/favicon.ico" />
<script src="@Url.Content("~/Scripts/jquery-3.0.0.min.js")"></script>
<script src="@Url.Content("~/Scripts/tether.js")"></script>
<script src="@Url.Content("~/Scripts/bootstrap.min.js")"></script>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body class="p-0">
@Html.Partial("Navbar")
<div class="container-fluid p-0">
@RenderBody()
</div>
@Html.Partial("_LoginModal",Model)
@Html.Partial("_GoogleAnalyticTracker")
</body>
</html>
Index.cshtml:
@model OgrenciEvi.Models.ViewModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Ana Sayfa";
}
@Html.Partial("LandingSection/SearchSection", Model)
_ViewStart.cshtml:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Index.cshtmlには、 '_Layout ="〜/ Views/Shared/_Layout.cshtml "; 'がありません。今私は追加しました。 ** _ ViewStart.cstml **にはこのコードスニペットがあります。 ディレクトリパスが正しいと確信しています。しかし、私は同じエラーがあります:/ –
Index.cshtmlファイルでは、 'Layout = ...' NOT '_Layout = ...'になります。 '_ 'は削除する必要があります。 –
はい、私は削除しましたが、私は同じです。また私は私の質問を編集しました。もう一度確認できますか? –