Copied to clipboard

Flag this post as spam?

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


  • Carlos Mosqueda 244 posts 435 karma points
    Nov 19, 2014 @ 20:18
    Carlos Mosqueda
    0

    An argument for using Macro Partial Views instead of just Partial Views

    So, I ran into an issue with using Partial View in my Views and development. 

    Based off of the training from Umbraco, developers are supposed to use Macro Partial View ionly for things that the content authors are entering into content, such as a slideshow directly into BodyText.  And then use Partial Views for things that Content Editors won't be adding into content (navigation, sidebar widgets, etc.)

    So the thing I like about using Macro Scripts or Macro Partial Views is that the Macros degrade gracefully, or at least they give you a message that states the Macro could not be loaded without killing the whole page.

    Solely using Partial Views to generate page elements, if your syntax is wrong in ANY way, the whole View is hosed.  So if you are just happening to develop or making changes to a Partial View on a live site (I know, not good practice), then your whole site pages with those Views trying to render the Partial View are completely broken until you can figure out the syntax error. 

    Is there a better way in Umbraco that if a Partial View can not be rendered correctly, that is does not kill the whole View or template?

    Thanks

     

    Carlos

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 19, 2014 @ 21:49
    Dennis Aaen
    0

    Hi Carlos,

    If you havenĀ“t seen the blogpost from Warren Buckly about Partials then maybe you can see when he mean that you should use Partial views or Partial macro views. http://creativewebspecialist.co.uk/2013/07/17/umbraco-mvc-is-the-macro-as-useful-in-v6-with-partials/

    And if you need to pass a parameter, then you want to use Partial View Macro Files as it is wrapped in a macro and can support taking a paramater passed from your template. If you don't need to pass a parameter to your view, then a Partial View can be used.

    Partial views: http://our.umbraco.org/documentation/Reference/Mvc/partial-views

    Partial view macros. http://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/

    Hope this helps,

    /Dennis

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 20, 2014 @ 08:07
    Dennis Aaen
    0

    Hi Carlos,

    Brain Flush has also written a blogpost about Umbraco: Partial View VS Partial View Macro.http://blogs.markglibres.com/2014/11/umbraco-partial-view-vs-partial-view.html

    /Dennis

     

  • Carlos Mosqueda 244 posts 435 karma points
    Nov 20, 2014 @ 21:16
    Carlos Mosqueda
    0

    @Dennis,

    I totally get why to use Partial View instead of Macro Partial Views and I agree with the direction.

    HOWEVER, if a Partial View breaks or let's say I needed to make a quick change to a Partial View and made a simple typo, the WHOLE page or all pages using that View/Template with that View break, unlike Macros where it outputs a message saying that the Macro could not be rendered. I was just wondering if Umbraco had a better way to handle Partial View breaks so the whole page does not break if the code in the Partial View is slightly off.

     

    -Carlos

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Nov 20, 2014 @ 22:06
    Nicholas Westby
    0

    You could always do this:

    @{try {
        @Html.Partial("~/Views/Partials/Whatever.cshtml", SomeModel)
    } catch { }}
    

    You could log the error in the catch block too if you like.

    By the way, Umbraco actually has a configuration setting to force the entire page to break when partial view macros break. Not something you would want, but just something to keep in mind (personally, I'd rather be made aware of an error so I can fix it rather than have it silently fail).

  • Carlos Mosqueda 244 posts 435 karma points
    Nov 20, 2014 @ 22:12
    Carlos Mosqueda
    0

    @Nicholas

    Hmmm. I guess we could to that on our Partials.  I guess in the catch we could just print out an error if the Partial did not load.

Please Sign in or register to post replies

Write your reply to:

Draft