Copied to clipboard

Flag this post as spam?

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


  • Jon Dunfee 199 posts 468 karma points
    May 07, 2014 @ 07:04
    Jon Dunfee
    0

    Passing Parameters From Partial View Macro to Partial View

    I have a macro created for Contact Form to allow content contributors to add content before and after the contact form.  Inside the PartialViewMacro I call the actual PartialView.

    The contact form has a reason dropdown I want to manage the options as media items.  I have a macro parameter to allow selection of multiple media items and now I need to figure out how to pass a collection (hashtable, something) of text/value options to the Partial I derive from the media items.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 07, 2014 @ 14:48
    Jeavon Leopold
    7

    Hi Jon,

    You can pass parameters like this:

    Partial View Macro

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        Html.RenderPartial(
            "~/Views/Partials/MyPartial.cshtml",
            Model.Content,
            new ViewDataDictionary(this.ViewData) {
                { "param1", "something" },
                { "param2", true }
            }
        );
    }
    

    Partial View

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    
    @{
    var param1 = (string)ViewData["param1"];
    var param2 =  (bool)ViewData["param2"];
    }
    

    This partial view is strongly typed and is passing the current page as the Model, so you can access properites like this: Model.GetPropertyValue<string>("myprop")

    Hope that's helpful?

    Jeavon

  • Jon Dunfee 199 posts 468 karma points
    May 07, 2014 @ 16:07
    Jon Dunfee
    0

    Thanks, is there a way to perform the same with Html.Action in the MacroView?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 08, 2014 @ 20:40
    Jeavon Leopold
    0

    You can pass parameters into your controller actions as shown here

Please Sign in or register to post replies

Write your reply to:

Draft