Search code examples
razorumbracoumbraco7

Template can't receive IList model


I'm writing an Umbraco application, and I need to send some Model to a page that inherits from the MasterPage like this:

@using ContentModels = App.Models.BlogPostViewModel
@inheritsUmbraco.Web.Mvc.UmbracoTemplatePage<IList<App.Models.BlogPostViewModel>>
@{
    Layout = "Master.cshtml";
}

But I'm getting the error:

The type 'System.Collections.Generic.IList' must be convertible to 'Umbraco.Core.Models.IPublishedContent'

Here is the controller:

public ActionResult GetBlogsByMonthId(int monthId)
{
    var rootNode = Umbraco.TypedContentAtRoot().First();
    var blogs = BlogService.GetBlogsByMonthId(rootNode, monthId);
    return View("~/Views/BlogArchivePage.cshtml", blogs);
}

What is wrong? Should I make a new page altogheter?


Solution

  • "IList" must derive from IPublishedContent to be able to use it with UmbracoTemplatePage. Instead, you can use UmbracoViewPage, which should work - see the code below :)

     @using ContentModels = App.Models.BlogPostViewModel
     @inheritsUmbraco.Web.Mvc.UmbracoViewPage<IList<App.Models.BlogPostViewModel>>
     @{
         Layout = "Master.cshtml";
      }