Error.cshtml 是部分视图还是什么?
我正在重构我的所有部分视图以使用前导下划线命名约定(当我开始时不知道这个约定,不想偏离这样一个简单的约定)。但我在 \Views\Shared 中遇到了生成的(razor、C#)“Error.cshtml”视图,我注意到它看起来可能是部分视图(没有 html/body 标签),但不遵循约定:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
<h2>
Sorry, an error occurred while processing your request.
</h2>
我还注意到它没有指定布局,但设置了 ViewBag.Title 属性,就好像布局将使用它一样。这是怎么回事?
I'm refactoring all my partial views to use the leading underscore naming convention (didn't know about this convention when I got started, don't want to deviate from such a plain convention). But I've come across the generated (razor, C#) "Error.cshtml" view in \Views\Shared and I noticed it looks like it may be a partial view (no html / body tags) yet doesn't follow the convention:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
<h2>
Sorry, an error occurred while processing your request.
</h2>
I also notice it doesn't specify a Layout, yet sets the ViewBag.Title
property as if it were going to be used by a Layout. What's the deal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奇怪的。我生成的 Error.cshtml 看起来像一个带有 HTML 正文的“正常”视图:
我认为在您的情况下,布局未设置为 null,因此将使用包含 HTML 包装元素的默认布局。
但这仍然是一个“正常”的观点(不偏颇)。
Strange. My generated Error.cshtml looks like a "normal" view with HTML body:
I think in your case the layout is not set to null, hence the default layout will be used that contains the HTML wrapping elements.
But it is still a "normal" view (not partial).