默认情况下如何更改布局?

发布于 2025-02-05 19:33:26 字数 684 浏览 3 评论 0原文

默认情况下,我在_viewstart.cshtml中更改布局,

@{
    Layout = "_Layout-empty";
}

但它是布局不起作用的。 _ layout正在工作。

然后,我删除_layout并获取错误:

invalidoperationException:布局视图'_layout'不可能是 位于。搜索以下位置: /Views/home/_layout.en.cshtml/views/home/_layout.cshtml /Views/shared/_layout.en.cshtml/views/shared/_layout.cshtml /pages/shared/_layout.en.cshtml/pages/shared/_layout.cshtml

i在_ViewStart中设置BreaKepoint,并且不活动:

“在此处输入图像说明”

为什么_viewStart.cshtml不起作用,并且不更改布局?

I change Layout by default in _ViewStart.cshtml

@{
    Layout = "_Layout-empty";
}

But it is layout does not work. _Layout is working.

Then I delete _Layout and get error:

InvalidOperationException: The layout view '_Layout' could not be
located. The following locations were searched:
/Views/Home/_Layout.en.cshtml /Views/Home/_Layout.cshtml
/Views/Shared/_Layout.en.cshtml /Views/Shared/_Layout.cshtml
/Pages/Shared/_Layout.en.cshtml /Pages/Shared/_Layout.cshtml

I set breakepoint in _ViewStart and it does not active:

enter image description here

Why does not _ViewStart.cshtml work and does not change layout?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦太阳 2025-02-12 19:33:26

invalidoperationException:无法找到布局视图'_layout'。搜索以下位置:/home/_layout.en.cshtml/views/home/_layout.cshtml/views/shared/shared/_layout/_layout.cshtml/views/shared/shared/_layout/_layout.cshtml/pages/pages/shared/_layout.enared/_layout.en en .cshtml/pages/shared/_layout.cshtml

错误意味着它正在寻找_layout.cshtml..cshtml..您可以在_viewstart.cshtml.lso中设置布局gloabaly。在_viewstart.cshtml中进行设置之前。

因此,您需要确保在浏览器中显示的视图不包含以下代码:

@{
    Layout = "_Layout";
}

InvalidOperationException: The layout view '_Layout' could not be located. The following locations were searched: /Views/Home/_Layout.en.cshtml /Views/Home/_Layout.cshtml /Views/Shared/_Layout.en.cshtml /Views/Shared/_Layout.cshtml /Pages/Shared/_Layout.en.cshtml /Pages/Shared/_Layout.cshtml

The error means it is looking for _Layout.cshtml.And you can set layout gloabaly in _ViewStart.cshtml.Also,you can set it in the view.And the setting in the view will be prior to the setting in _ViewStart.cshtml.

So you need to make sure the view you displayed in browser doesn't contain the following code:

@{
    Layout = "_Layout";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文