Copied to clipboard

Flag this post as spam?

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


  • nickornotto 397 posts 900 karma points
    Nov 06, 2015 @ 08:17
    nickornotto
    0

    How to use custom model in macro partial?

    I have a macro where I have a contact form.

    Because the contact form uses Contact model I want my macro to be strongly typed.

    How to make the macro to accept custom model?

    This doesn't work:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage<MyWebsite.Models.ContactModel>
    

    It says PartialViewMacroPage cannot be used with typed arguments

    I'm using a grid and macro is inserted to the page via macro item of the grid

  • Carl Jackson 139 posts 478 karma points
    Nov 06, 2015 @ 17:18
    Carl Jackson
    0

    I don't think a model can be passed into a macro view only macro parameters/

    If you want a strongly typed model in there you would need to call

    @Html.Action("action", "controller")
    

    In the macro and they work work with a strongly typed model from the returned view.

    Alternatively extend PartialViewMacroPage with your model and then inherit that? as this essentially is already the model of a UmbracoViewPage

    public abstract class PartialViewMacroPage : UmbracoViewPage<PartialViewMacroModel>
      {
    

    Thanks.

    Carl

  • nickornotto 397 posts 900 karma points
    Nov 10, 2015 @ 17:47
    nickornotto
    0

    I think I just use a standard form and macro without the model :(

    Thanks anyway

Please Sign in or register to post replies

Write your reply to:

Draft