模板无法接收 IList 模型
Template can't receive IList model
我正在编写 Umbraco 应用程序,我需要将一些模型发送到从 MasterPage 继承的页面,如下所示:
@using ContentModels = App.Models.BlogPostViewModel
@inheritsUmbraco.Web.Mvc.UmbracoTemplatePage<IList<App.Models.BlogPostViewModel>>
@{
Layout = "Master.cshtml";
}
但我收到错误消息:
The type 'System.Collections.Generic.IList' must be convertible to '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(rootNode, monthId) return 是 IPublishedContent 列表吗?我在做类似的事情:-
mainBlogPageContent.Children.OrderByDescending(x => x.CreateDate).Take(numberOfArticles).ToList()
然后将其传递到我的部分视图中:-
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IList<IPublishedContent>>
我忘记添加 'ToList' - 添加这个解决了我的问题。
我正在编写 Umbraco 应用程序,我需要将一些模型发送到从 MasterPage 继承的页面,如下所示:
@using ContentModels = App.Models.BlogPostViewModel
@inheritsUmbraco.Web.Mvc.UmbracoTemplatePage<IList<App.Models.BlogPostViewModel>>
@{
Layout = "Master.cshtml";
}
但我收到错误消息:
The type 'System.Collections.Generic.IList' must be convertible to '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(rootNode, monthId) return 是 IPublishedContent 列表吗?我在做类似的事情:-
mainBlogPageContent.Children.OrderByDescending(x => x.CreateDate).Take(numberOfArticles).ToList()
然后将其传递到我的部分视图中:-
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IList<IPublishedContent>>
我忘记添加 'ToList' - 添加这个解决了我的问题。