Copied to clipboard

Flag this post as spam?

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


  • Chris 34 posts 134 karma points
    Apr 10, 2015 @ 17:15
    Chris
    0

    Render Macro using MVC

    I'm trying to setup a contact form using MVC partial views and a macro, but although I can see my form correctly when using the content editor when browsing the site as a normal user the form won't display. This is what I have so far:

    • Created a new partial view called RequestCallBack_Macro in Views\MacroPartials which simply calls to a controller:
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @Html.Action("ShowRequestCallBackForm""ContactFormsSurface")
    • Created a new macro called RequestCallBack with the MVC Partial View set to RequestCallBack_Macro
    • Created a Controller called ContactFormsSurfaceController, with a single child action called ShowRequestCallBackForm that returns a partial view called _RequestCallBackForm
    • Created a View model class that has a single string property to hold the RichText values
    In the Razor view I'm then rendering the Rich text editor field using this:
    @Html.Raw(@Model.BodyText)
    

    However when the HTML renders this is what I get:

    <!-- <?UMBRACO_MACRO macroAlias="RequestCallBack" /> -->
    

    When I add the Macro within the Umbraco content editor I can see the form being displayed correctly, however it is not displaying outside the editor. Does anyone know ow do I get this macro to display correctly?

    Any help is greatly appreciated

  • Yakov Lebski 591 posts 2346 karma points
    Apr 12, 2015 @ 21:04
    Yakov Lebski
    0

    Try use @Umbraco.Field("bodyText")

  • Chris 34 posts 134 karma points
    Apr 13, 2015 @ 10:07
    Chris
    100

    As I'm using a custom ViewModel with no access to the @Umbraco helper, in the end I put this into my controller action:

    umbraco.library.RenderMacroContent(src.BodyText, src.Id)
    
Please Sign in or register to post replies

Write your reply to:

Draft