Copied to clipboard

Flag this post as spam?

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


  • Dan White 206 posts 510 karma points c-trib
    Dec 07, 2012 @ 23:51
    Dan White
    0

    MVC Partial or Helper (4.11)

    I'm working on implementing sidebar widgets into a site. For every page, editors can choose which widgets to use using the multi-media picker. Each widget type has a docType and Partial for the markup. The widget Partials are loaded based on their docType. In order to do this, I have a sidebar Partial which basically acts as a calls the individual widget Partials.

     

    // sidebar Partial
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @{
        var widgets = Umbraco.TypedContent( Model.GetPropertyValue<string>("widgets").Split(',') );
        foreach (var widget in widgets){
            @Html.Partial("Widgets/" + widget.DocumentTypeAlias, widget);
        }
    }
    

     

    Called like:

    @Html.Partial("Widgets/Sidebar", @Model.Content);
    

    However, doesn't seem like something that should be a partial, but rather a helper/function or something. I'm pretty much a newb, so I'm wondering if it's best left as a partial or how to create it as a helper?

    It might be called like:

    @GlobalHelpers.renderSidebar(Model.Content.GetPropertyValue("widgets"));

    Any help would be great.

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Dec 08, 2012 @ 13:47
    Jeroen Breuer
    0

    I would also like to know what's best here. Currently we're using partial views for it, but I'm not sure if it's better than a helper.

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies