Umbraco:无法将源内容类型 ArticleItem 绑定到模型内容类型 ArticlesMain

Umbraco: Cannot bind source content type ArticleItem to model content type ArticlesMain

这是我们第一次尝试 Umbraco,我们正在按照官方教程创建一个 Arcticle/News 功能作为示例。

我们基本上是从头开始的here

所以,首先我们创建了一个主页,然后是一个母版页,以及介于两者之间的所有内容,直到我们到达 this 点。

显示的一切都正常,我们有一个概览,Macro/Partial 视图运行良好。

但是当我们想要导航到实际的 ArticleItem 时,我们 运行 进入了标题中提到的错误。

Cannot bind source content type Umbraco.Web.PublishedContentModels.ArticlesItem to model content type Umbraco.Web.PublishedContentModels.ArticlesMain. Both view and content models are PureLive, with same version. The application is in an unstable state and should be restarted.

现在,我的猜测是作为 ArticlesMain 模板的母版页存在问题,这强制该模型 used/passed 到 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/>
}

至于文档类型,它们看起来和教程截图中的一模一样,我当然也可以提供这些,包括设置的权限。

我从 Umbraco 官方论坛得到了一些帮助,结果发现我确实犯了一个简单的错误。

如果有人偶然发现这个问题,我就把它留在这里:

this is caused as the model that is used in the view is not of the correct type. You used Layout = "ArticleMain.cshtml" in your view for the ArticleDetails which causes the ArticleMain.cshtml to be used as a parent view. This view needs a model of type ArticleMain. Switching to "Layout=Master.cshtml" should solve the issue. At least this seems to be the master view in the tutorial.

Umbraco forum comment