Copied to clipboard

Flag this post as spam?

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


  • Kris Janssen 210 posts 569 karma points c-trib
    Mar 31, 2014 @ 21:39
    Kris Janssen
    0

    UmbracoHelper in Razor using @Umbraco?

    Simple, as the subject says...

    I get validation errors when trying to save a macroScript containing things such as:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @Umbraco.TypedMedia(9999)
    

    Am I missing something?

    You cannot just:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Mar 31, 2014 @ 21:50
    Jeavon Leopold
    100

    Hi Kris,

    To use @Umbraco you need to be using either a MVC View (template), a Partial View or a Macro Partial View.

    DynamicNodeContext is used by the legacy "Razor Macros", if have to use a Razor Macro, then the helper is @Library

    MVC documentation is here but essentially don't use the "Scripting Files" tree unless you need to for legacy support.

    Does that help?

    Jeavon

  • Kris Janssen 210 posts 569 karma points c-trib
    Mar 31, 2014 @ 21:52
    Kris Janssen
    0

    Hi Jeavon,

    That indeed confirms what I was afraid of.

    I' m working on a site still using MasterPages instead of MVC and a whole bunch of Scripting Files...

    Maybe it' s about time to overhaul the whole thing :s

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Mar 31, 2014 @ 21:56
    Jeavon Leopold
    0

    You can still use the @Umbraco helper with WebForms, that is what the Macro Partial View is mainly for, it supersedes the the Razor Macro.

    In fact you can take a existing Razor macro code, place into a new Macro Partial View, make the required updates, e.g. @Library to @Umbraco and then switch the Macro itself from the Scripting File to the new Macro Partial View and not even need to change the MasterPage template at all.

  • Kris Janssen 210 posts 569 karma points c-trib
    Mar 31, 2014 @ 22:10
    Kris Janssen
    0

    Great stuff!

    Somehow I wasn't aware this was possible...

    Thanks!

  • 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