x First time here? Check out the FAQ
Join us a the Umbraco event of the year - get your Codegarden 14 early bird ticket today
  • Avatar6posts26karma

    Outputting Path to Uploader Image on Document Type in Partial View

    Kevin started this topic March 10, 2012 @ 02:28

    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 posted this reply March 10, 2012 @ 01:17

    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 posted this reply March 24, 2012 @ 03:43

    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 posted this reply March 24, 2012 @ 04:48

    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 login or Sign up To post replies