Copied to clipboard

Flag this post as spam?

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


  • Kevin 6 posts 26 karma points
    Mar 10, 2012 @ 02:28
    Kevin
    0

    Outputting Path to Uploader Image on Document Type in Partial View

    Hi all,

    I'm trying to output an image on a partial view of a page, I seem to be able to get all the other properties. But when I try and get my property Image which is an Uploader nothing is coming back.

    I've uploaded an image in the CMS fine. Are there any properties I need to access further??

    Also is there any SDK or a place where I can get the class definitions and members of all the property classes?

    @inherits RenderViewPage
    @using Umbraco.Cms.Web;

    <ul>
    @foreach (var item in Model.ChildContent().OrderBy(x => x.AsDynamic().DisplayOrder))
    {
        var dynamicItem = item.AsDynamic();

        var image = dynamicItem.Image;
        var bodyText = dynamicItem.BodyText;
        var fromText = String.Format("{0}, {1}", dynamicItem.From, dynamicItem.Location);
      
        <li>
            <img src="@image" alt="@fromText" />
            @Html.Raw(bodyText)
            <span>@fromText</span>
        </li>       
    }
    </ul>

    Thanks in advance for any help,

    Kevin

  • Mysterious 27 posts 47 karma points
    Mar 10, 2012 @ 13:17
    Mysterious
    0

    can you post what the "image" variable contains?

    if you are using Visual Studio then you can attach it to the process to be able to debug your razor script and use the "Immediate window"
    or
    simply just put <p>@image</p> above your image tag so you can see what is the value of the variable

     

  • Kevin 6 posts 26 karma points
    Mar 24, 2012 @ 03:43
    Kevin
    0

    Hi,

    I still can't get this to work, I deleted the image property and called one mainImage. I've output it and there's an empty string. Code for partial view is below:

    @inherits RenderViewPage
    @using Umbraco.Cms.Web;

    <ul>
    @foreach (var item in Model.ChildContent().OrderBy(x => x.AsDynamic().DisplayOrder))
    {
        var dynamicItem = item.AsDynamic();

        var mainImage = dynamicItem.MainImage;
        var bodyText = dynamicItem.BodyText;
        var fromText = String.Format("{0}, {1}", dynamicItem.From, dynamicItem.Location);
      
        <li>
            <p>@mainImage</p>

            @if (!String.IsNullOrEmpty(mainImage))
            {
                <img src="@mainImage" alt="@fromText" />
            }       
            @Html.Raw(bodyText)
            <span>@fromText</span>
        </li>       
    }
    </ul>

  • Kevin 6 posts 26 karma points
    Mar 24, 2012 @ 04:48
    Kevin
    0

    Ok I've figured this out, need to get the Media URL like this:

    var mainImageUrl = Umbraco.GetMediaUrl(dynamicItem.Id, "mainImage");

    Where mainImage is the name of my property.

Please Sign in or register to post replies

Write your reply to:

Draft