我收到此错误:
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Scripts".
当我在家庭控制器上放置[授权]时,我才会收到此错误。
[Authorize]
public ViewResult Index()
{
return View();
}
为了解决问题,我已经删除了除此之外的_layout页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container body-content">
@RenderBody()
</div>
</body>
</html>
Home的Index视图只是这个:
hello world
如果我删除[授权],则没有错误。
答案 0 :(得分:2)
您的原始视图声明了“脚本”部分。您需要将其删除或将此代码添加到您的布局页面中:
@RenderSection("scripts", required: false)