gpt4 book ai didi

asp.net-mvc - MVC3 - RenderSection 内的 RenderPartial 不起作用

转载 作者:行者123 更新时间:2023-12-01 01:29:10 27 4
gpt4 key购买 nike

我正在处理 MVC3/Razor 页面,在我的 _layout 中我有

  @RenderSection("relatedBooksContainer", false)

在另一个页面中,我将该部分用于:
@section relatedBooksContainer
{
@{ Html.RenderPartial("~/Views/Shared/Bookshelf.cshtml", Model.Books);}
}

这不起作用。从我读过的内容来看,RenderSection 只会深入一层 - 它在相关部分中没有 Html.RenderPartial 的概念,只会返回一个空白区域。我在 http://forums.asp.net/t/1590688.aspx/2/10 上读到的解决方法是使用 RenderPage 并将返回的 HTML 提交到一个字符串,然后在渲染部分输出该字符串......这有效!也就是说,在我将模型传递给部分页面之前,它会抛出一个错误说:

The model item passed into the dictionary is of type 'TheBookshelf.ViewModels.BookshelfViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.List`1[TheBookshelf.EntityModel.Book]'.



任何人都知道为什么会发生这种情况?有没有其他方法可以实现这一目标?

最佳答案

试试 @Html.Partial 反而

@section relatedBooksContainer
{
@{ Html.Partial("~/Views/Shared/Bookshelf.cshtml", Model.Books);}
}

关于asp.net-mvc - MVC3 - RenderSection 内的 RenderPartial 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5916996/

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