我想知道为什么我的一个观点出现错误"未定义的部分:" 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>
答案 0 :(得分:0)
C鲍尔的问题是有效的,你是否从RenderPage()渲染这个视图?
您无法在模板中定义由其呈现的部分 RenderPage()。部分实际上只能从实际视图中定义 从Controller传递的模板。