简而言之,不,局部视图不需要单独的模型。您可以简单地将模型传递给每个部分,如下所示:
@Html.Partial("~/Views/Shared/_CorporateEvents.cshtml", modelGoesHere);
您的控制器从contentful中获取多个条目,每个条目只包含一个条目
Asset
. 这些应该是你在旋转木马里的物品吗?
如果是这样,我会创建如下视图:
<div class="carousel-inner">
@foreach(var slide in Model) {
@Html.Partial("~/Views/Shared/_CorporateEvents.cshtml", slide);
}
</div>
部分观点是这样的:
<div class="item">
<img source src="@image.EventImages.File.Url" type="image"
alt="Your browser does not support the image tag." />
</div>
<contentful-image>
taghelper而不是img标记来利用内容图像API。然后,可以用以下内容替换局部视图:
<div class="item">
<contentful-image url="@image.EventImages.File.Url" width="850" height="700"
alt="Your browser does not support the image tag." />
</div>
只需添加
@addTagHelper *, Contentful.AspNetCore
给你的
_ViewImports
文件
https://www.contentful.com/developers/docs/net/tutorials/aspnet-core/