gpt4 book ai didi

c# - 如何将一个部分传递给部分布局?

转载 作者:行者123 更新时间:2023-12-02 00:04:32 25 4
gpt4 key购买 nike

在 ASP.net MVC 5 中,我们可以使用

将部分传递给布局
@section AnySection{
//section code here
}

并在 Layout by 中渲染它

@RenderSection("AnySection", required: false)

但是我们如何才能将该部分再次传递给该布局中的部分内容呢?请参阅下图以供引用 how can we pass that section to partial?subheader-v1 是我的布局中的局部 View 我用许多局部 View 制作了我的布局。当我按照上面的图片中提到的那样尝试时,它给了我这个错误

The file "~/Views/Shared/partials/_subheader/subheader-v1.cshtml" cannot be requested directly because it calls the "RenderSection" method.'

最佳答案

您没有将部分传递给布局。布局决定了哪些部分应该(或可以)在 View 中呈现……它还决定了该部分应该呈现在 View 中的哪个位置。

来自 MS Documentation :

A layout can optionally reference one or more sections, by calling RenderSection. Sections provide a way to organize where certain page elements should be placed.

部分在部分 View 中不起作用,这是设计使然。您需要将 RenderSection 移动到您的布局,并将部分主体移动到您的 View 。参见 this question获取更多信息。

关于c# - 如何将一个部分传递给部分布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61052525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com