加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – MVC3 – RenderSection中的RenderPartial不起作

发布时间:2020-12-16 10:00:16 所属栏目:asp.Net 来源:网络整理
导读:我正在研究一个MVC3 / Razor页面,在我的_layout中我有 @RenderSection("relatedBooksContainer",false) 在另一个页面中,我使用该部分: @section relatedBooksContainer{@{ Html.RenderPartial("~/Views/Shared/Bookshelf.cshtml",Model.Books);} } 这不起作
我正在研究一个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);} 
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读