简体   繁体   中英

Umbraco page name instead of page id

I am pondering over an Umbraco related problem.

In the admin I am allowing the uploading on an image using the Upload Type Property

Then the user can select a page on the website using the Content Picker Type Property.

The image is then wrapped with the following anchor tag code

The problem is that the link returns the id of the selected page ie http://listerivf.whclpreview.com/1107 and not http://listerivf.whclpreview.com/egg-donors.aspx , can anyone help me with the anchor tag code href code, thanks!

<a href="<%= umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("imageLink").Value %>">
      <umbraco:Image runat="server" field="au1" width="302" height="215" class="thumbnail" /></a>

Here is how I handle these images. I often want to show my image markup (often has wraping visual elements) only if an image is selected. So I use:

@{
    var myImageSrc = Utilities.GetMediaSrcOrEmptyString(Model.image.ToString());
}

This function is:

public static string GetMediaSrcOrEmptyString(string nodeId)
{
    if (nodeId != "")
    {
        dynamic mediaItem = new DynamicNode(Convert.ToInt32(nodeId));
        return mediaItem.umbracoFile;
    }
    return "";
}

Then I can use the following to print my markup:

@if (myImageSrc != "")
{
    <div class="myClassForImage">
        <img src="/ImageGen.ashx?width=465&image=@imageSrc" width="465" alt="@Model.someField"/>
    </div>
    <br/>
}

Very simple, but quite usefull!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM