Copied to clipboard

Flag this post as spam?

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


  • Jamie Wu 19 posts 79 karma points
    Jun 03, 2013 @ 08:30
    Jamie Wu
    0

    Get URL of Content Picker in v6

    Any ideas? 

     

  • Ian Black 54 posts 230 karma points
    Jun 04, 2013 @ 16:18
    Ian Black
    0

    Hi Jamie,

    The content picker returns the node ID of the content item selected.
    To get the URL we just need to do a quick check on the node ID returned.

    var strURL = Model.NodeById(propertyAlias).Url;

    'propertyAlias' is the alias given to the content picker in the document type.

    Hope that helps,
    Ian.

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Jun 04, 2013 @ 16:33
    Ali Sheikh Taheri
    0

    try this

    Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("propertyAlias")).Url

  • Jamie Wu 19 posts 79 karma points
    Jun 05, 2013 @ 13:25
    Jamie Wu
    0

    Thanks Ian and Ali. 

    I tried your codes but with no luck :( and got the following errors:

     Ian's

    CS1061: 'Umbraco.Web.Models.RenderModel' does not containI a definition for 'NodeById' and no extension method 'NodeById' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)

    Ali's

    System.NullReferenceException: Object reference not set to an instance of an object.

    I reckon if v6 changes the api to get Node.

     


  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Jun 05, 2013 @ 13:48
    Ali Sheikh Taheri
    1

    try this, first you need to check if the propertyAlias has value then you can use the api to retrieve the Url. 

    if(Model.Content.HasValue("propertyAlias"))
    {
      @Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("propertyAlias")).Url
  • Ian Black 54 posts 230 karma points
    Jun 05, 2013 @ 15:52
    Ian Black
    0

    Assuming your using Razor here's a little snippet:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
    if (@Model.HasProperty("myAliasURL") && @Model.GetProperty("myAliasURL").Value != String.Empty)
    {
    var strURL = @Model.NodeById(@Model.myAliasURL).Url;
    }

    Cheers,
    Ian. 

  • Jamie Wu 19 posts 79 karma points
    Jun 07, 2013 @ 02:10
    Jamie Wu
    0

    Hi Ian,

    I have tried your snippet and had an error:

     

    CS0234: The type or namespace name 'NiceUrl' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)

     

    Line 10 if (!String.IsNullOrEmpty(nodeId))
    Line 11:             {
    Line 12: var publishedContent = Umbraco.NiceUrl(Convert.ToInt32(nodeId)); Line 13:                 if (!String.IsNullOrEmpty(publishedContent) && publishedContent != "#")
    Line 14:                 {
  • Ian Black 54 posts 230 karma points
    Jun 07, 2013 @ 10:00
    Ian Black
    0

    Could you try:

    var publishedContent = umbraco.library.NiceUrl(Convert.ToInt32(nodeId));
  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Jun 07, 2013 @ 12:16
    Ali Sheikh Taheri
    101

    Hi Jamie and Ian

    Umbraco.NiceUrl is for the old API.

    as I mentioned before you can use new API which is much faster and when you upgrade to newer version will not break.

    did you get any luck with this?

    if(Model.Content.HasValue("propertyAlias"))
    {
     
    @Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("propertyAlias")).Url
    }

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies