cshtml视图";未定义的部分:“;特征d2”;
本文关键字:特征 d2 视图 quot 未定义 cshtml | 更新日期: 2023-09-27 18:25:10
我想知道为什么我的一个视图会出现错误"Section not defined:"featured2"。布局的路径是正确的,我在视图中定义了featured2部分。
查看
@using System.Data;
@using System.Data.SqlClient;
@{
ViewBag.Title = "Attempted Unauthorized Access";
Layout = "../Shared/Layout2.cshtml";
string whoareyoupeople = User.Identity.Name.ToString();
DateTime date = DateTime.Now;
string myerrorstring = "User " + whoareyoupeople + " attempted unauthorized access on " + date + ".";
string fileName = "C:''BillingExport''SECURITY''seclog.txt";
using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write)){
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(myerrorstring);
}
}
}
@section featured2 {
<body>
<head></head>
<center><h2 style="color:red">Access Denied for user @User.Identity.Name. You are not authorized to view this application.</h2></center>
</body>
}
布局2
@{
ViewBag.Title = "Layout2";
}
<link runat="server" rel="icon" href="../Content/images/eifavicon.ico" type="image/x-icon" />
@RenderSection("featured2")
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
<script>
browsername = navigator.appName;
if (browsername.indexOf("Microsoft") != -1) {
browsername = "MSIE";
document.write("<p id='indent2'>You're viewing this page using Internet Explorer. Please use a supported browser (<a href='https://www.google.com/chrome/browser/'>Chrome</a>, <a href='https://www.mozilla.org/en-US/firefox/new/'>Firefox</a>)</p>");
}
</script>
C Bauer的问题是有效的,你是从RenderPage()渲染这个视图吗?
不能在模板中定义由渲染的部分RenderPage()。截面实际上只能从实际视图中定义正在从控制器传递的模板。
类似堆栈溢出问题/答案