【发布时间】:2018-07-06 10:15:17
【问题描述】:
这是我们第一次尝试 Umbraco,我们正在按照官方教程创建一个北极/新闻功能作为示例。
我们基本上都是从上面开始here
所以,首先我们创建了一个主页和一个母版页,以及介于两者之间的所有内容,直到我们到达this 点。
显示的一切都正常,我们有一个概览,宏/局部视图运行良好。
但是当我们想要导航到实际的 ArticleItem 时,我们遇到了标题中提到的错误。
无法将源内容类型 Umbraco.Web.PublishedContentModels.ArticlesItem 绑定到模型内容类型 Umbraco.Web.PublishedContentModels.ArticlesMain。视图和内容模型都是 PureLive,具有相同的版本。应用程序处于不稳定状态,应重新启动。
现在,我的猜测是 Masterpage 作为 ArticlesMain 模板是一个问题,这会强制使用该模型/将其传递给 ArticlesItem 页面。但是我的 MVC 已经很生锈了,所以我现在似乎无法自己找到解决方案。
使用的代码是从教程中 1:1 复制的,以确保我们没有搞砸任何东西,但到目前为止还没有骰子。我们还在 Umbraco CMS 中做了所有事情,我们的 IDE (VS) 没有被使用。
/Views/ArticlesMain.cshtml
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<ContentModels.ArticlesMain>
@using ContentModels = Umbraco.Web.PublishedContentModels; @{ Layout = "HomePage.cshtml"; }
<div id="main-container">
<div id="main" class="wrapper clearfix">
<section>
<h2>@Umbraco.Field("articlesTitle")</h2>
<p>@Umbraco.Field("articlesBodyText")</p>
<p>@Umbraco.RenderMacro("listArticles")</p>
</section>
</div>
<!-- #main -->
</div>
<!-- #main-container -->
/Views/ArticlesItem.cshtml
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<ContentModels.ArticlesItem>
@using ContentModels = Umbraco.Web.PublishedContentModels; @{ Layout = "ArticlesMain.cshtml"; }
<h1>@Umbraco.Field("articlesTitle")</h1>
<article>
<h2>@Umbraco.Field("createDate")</h2>
<p>@Umbraco.Field("articleContents")</p>
</article>
/Views/MacroPartials/listArticles.cshtml
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var selection = CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc");
@* OrderBy() takes the property to sort by and optionally order desc/asc *@
}
@foreach (var item in selection)
{
<div class="article">
<div class="articletitle"><a href="@item.Url">@item.Name</a></div>
<div class="articlepreview">@Umbraco.Truncate(@item.ArticleContents,100) <a href="@item.Url">Read More..</a></div>
</div>
<hr/>
}
至于文档类型,它们看起来与教程的屏幕截图完全相同,我当然也可以提供这些,包括设置的权限。
【问题讨论】:
-
您在哪里以及如何使用 ArticlesItem.cshtml?您应该只有 ArticlesMain 模板,在其中您将使用该页面的子级呈现宏。就是这样。
标签: html asp.net-mvc model umbraco