我正在写一个应用一把umbraco,我需要一些型号发送到这样从母版继承的页面:
@using ContentModels = App.Models.BlogPostViewModel
@inheritsUmbraco.Web.Mvc.UmbracoTemplatePage<IList<App.Models.BlogPostViewModel>>
@{
Layout = "Master.cshtml";
}
但我得到的错误:
类型“System.Collections.Generic.IList”必须转换为“Umbraco.Core.Models.IPublishedContent”
这里是控制器:
public ActionResult GetBlogsByMonthId(int monthId)
{
var rootNode = Umbraco.TypedContentAtRoot().First();
var blogs = BlogService.GetBlogsByMonthId(rootNode, monthId);
return View("~/Views/BlogArchivePage.cshtml", blogs);
}
怎么了?我应该做一个新页共?
“的IList”必须从IPublishedContent派生出能够与UmbracoTemplatePage使用它。相反,你可以使用UmbracoViewPage,这应该工作 - 看下面的代码:)
@using ContentModels = App.Models.BlogPostViewModel
@inheritsUmbraco.Web.Mvc.UmbracoViewPage<IList<App.Models.BlogPostViewModel>>
@{
Layout = "Master.cshtml";
}
请问您BlogService.GetBlogsByMonthId(根节点,monthId)返回一个列表IPublishedContent?我在做类似的东西: -
mainBlogPageContent.Children.OrderByDescending(x => x.CreateDate).Take(numberOfArticles).ToList()
然后将它传递到我的局部视图: -
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IList<IPublishedContent>>
我忘了加“ToList” - 添加此固定我的问题。