Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kenno 1 post 21 karma points
    May 07, 2015 @ 01:11
    Kenno
    0

    Does MVC UmbracoTemplateView<TModel> support controllers that return IContent?

    Hi All

    We're plugging in MVC5 into Umbraco 7.

    Just to check my understanding, I have a RenderModel that is returning IPublishedContent, and it doesn't show unpublished items in Preview mode, correct?

    ```C# List

    if (@Model != null && @Model.Content != null)
    {
        heroContent = @Model.Content.Children
            .Where(c => c.DocumentTypeAlias.Equals("HomePageHero", StringComparison.OrdinalIgnoreCase))
            .Where(x => x.IsVisible() || @UmbracoContext.InPreviewMode) // <-- this has no effect?
            .ToList();
    }
    else
    {
        // this so that it can be rendered in the editor without error
        heroContent = new List<IPublishedContent>();
    }
    

    ```

    If I create my own controller (returning IContent), it works OK

    ```C# @inherits UmbracoTemplatePage @using My.UmbracoServices @using My.UmbracoServices.Controllers @{

    // constructor logic here AGGHHH no convention
    var context = new MyUmbracoContext(@UmbracoContext.InPreviewMode);
    var contentService = new MyContentService(context, @UmbracoContext.Application.Services.ContentService);
    var mediaService = new MyMediaService(new mediaService);
    var controller = new HeroPromoController(mediaService, contentService);
    
    var heroContent = controller.GetHeroMediaItems(@Model.Content.Id);         
    

    }

    @foreach (var promo in heroContent) { }

    ```

    Q. Is there a base view

Please Sign in or register to post replies

Write your reply to:

Draft