This post shows you how you can get to the IPublishedContent item from a Content Pick Macro Parameter in Umbraco. It is a guest post by Nisreen Almasri from Sweden.

The scenario

I feel my question is silly and can be answered straightforward but after googling and searching here and there, discover that nothing is silly with Umbraco:)

I have a login form and many types of members, according to the type of member (which group he belongs to) must be forwarded to a specific page. and because we have a multi-language website so I can use hardcoded URLs because the name of the page varies.

to summarize that, I have all related pages as macro parameters (content picker) but I need to reach the node id for each to use this code

Response.Redirect(library.NiceUrl(Convert.ToInt32(Id)));

What I tried at first

I used this at the beginning

var urlDownload = Model.MacroParameters["urlDownload"];

But it returns the UDI, not the node ID, because my version of Umbraco has property value converters enabled.

"umb://document/f875c2c828d04a2dbdb2dcf80d841a9f"

The solution

Finally, the solution was using this piece of code:

var contDownload = Umbraco.TypedContent(urlDownload);

and I could reach the id easily...

Response.Redirect(library.NiceUrl(Convert.ToInt32(contDownload.Id)));

Final code

Here is the whole code:

@{
    var urlDownload = Model.MacroParameters["urlDownload"];
    var urlSale = Model.MacroParameters["urlSale"];
    var urlExport = Model.MacroParameters["urlExport"];
    var urlAD = Model.MacroParameters["urlAD"];
    var contDownload = Umbraco.TypedContent(urlDownload);     var contSale = Umbraco.TypedContent(urlSale);     var contExport = Umbraco.TypedContent(urlExport);     var contAD = Umbraco.TypedContent(urlAD);
    var currentMember = User.Identity.Name;
    var t = Roles.GetRolesForUser(currentMember).FirstOrDefault();
    if (Members.GetCurrentLoginStatus().IsLoggedIn && Request.UrlReferrer != null)     {         switch (t)         {             case "Download":                 Response.Redirect(library.NiceUrl(Convert.ToInt32(contDownload.Id)));                 break;             case "Sale":                 Response.Redirect(library.NiceUrl(Convert.ToInt32(contSale.Id)));                 break;             case "Exporting":                 Response.Redirect(library.NiceUrl(Convert.ToInt32(contExport.Id)));                 break;             default:                 Response.Redirect(library.NiceUrl(Convert.ToInt32(contAD.Id)));                 break;         }     } }

Nisreen Almasri

Nisreen is a Software and Umbraco developer at Empir Group AB in Sweden

Proudly sponsored by

Moriyama

  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.
AppVeyor

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.
elmah.io

  • elmah.io is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.
uSkinned

  • More than a theme for Umbraco CMS, take full control of your content and design with a feature-rich, award-nominated & content editor focused website platform.
UmbHost

  • Affordable, Geo-Redundant, Umbraco hosting which gives back to the community by sponsoring an Umbraco Open Source Developer with each hosting package sold.