Copied to clipboard

Flag this post as spam?

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


  • Robert J. Bullock 386 posts 405 karma points
    May 16, 2013 @ 19:07
    Robert J. Bullock
    0

    Render Razor Macro Directly in Razor View?

    Is there a way to render a macroScript direclty with the filename in a *Razor View*? I see there's a way to do it with master pages, but can't figure it out with Razor templates...

  • gary 385 posts 916 karma points
    May 17, 2013 @ 00:24
    gary
    0

    hi Robert

    if you take the macro out, put the code into a partial view, then call @Html.Partial("yourPartialName") you should be cooking with gas, fhat is if you are using mvc.

    if webforms, its.a.macroscript i believe, but you should be able to call direct from the file.

    hope it helps

    g

  • Robert J. Bullock 386 posts 405 karma points
    May 17, 2013 @ 06:10
    Robert J. Bullock
    0

    Yes, I discovered that... But then I discovered that a ton of code changes were required to go from a simple Razor macro to a Partial View! Things like having to use "Model.Content.Field" vs. "Model.Field" and for some reason having to use "mntp.link.InnerText()" where just "mntp.link" worked fine with the Razor macro. It's a whole new world with MVC, but I am excited that I can add some logic to my template generation... it's pretty cool and a real boon for responsive design!

  • gary 385 posts 916 karma points
    May 17, 2013 @ 13:28
    gary
    0

    hi Robert

    some of what you say is true, but those code changes are due mainly to changes in the version of umbraco.

    The code used in a normal mvc view is exactly the same as you would use in your partial, so take your whole view, make the partial from that code and call the partial from the original view  and it will work.

    I use this to make my partials, write the code in the view, if the code will be repeated elsewhere, then create the partial, cut the code block, paste into the partial and call the partial in the orignal view and wherever else it is needed.

    Hope that helps, dive in, give it a try and you can leave macros behind.

    regards

    gary

     

     

  • Robert J. Bullock 386 posts 405 karma points
    May 17, 2013 @ 14:03
    Robert J. Bullock
    0

    It does help... just confused by some of the new things i didn't know about like calling objects with ".AsDyanmic()" and such... Yeah, I am sick of having dozens of macros to do simple things like change headines on the fly, navigation, etc. Gets confusing. Already enjoying the more integrated and structurally solid MVC way...

Please Sign in or register to post replies

Write your reply to:

Draft