I'm cycling through the children of the current page, and I want to render an image (type upload with alias myImage), and some text (type textarea with alias myText). Currently I have this:
@foreach (var item in DynamicModel.Children) { <div class="product"> <img src="@item.myImage" alt="Photo of @item.Name" /> <h2>@item.Name</h2> <p>@item.myText</p> </div> }
But when I visit the page, the image is not rendered and the alt attribute is shown. All other fields work as expected. I'm using Umbraco 5 RTM build 5.0.310.16
@foreach (var item in DynamicModel.Children) { <div class="product"> <img src="@Umbraco.GetMediaUrl(item.Id, "myImage")" alt="Photo of @item.Name" /> <h3>@item.Name</h3> <p>@item.myText</p> </div> }
So for anyone wondering how to get an image from and Upload property, the sintax is @Umbraco.GetMediaUrl(page.Id, "propertyAlias")
The problem is that now this is not working for every case. In a level 3 page I can get the image from the children at level 4. However, in another page at level 2, I cannot get images from children in level 3. I get this error (my translation) "Not valid URL: cannot analyze hostname" System.UriFormatException appears in the details. Any ideas?
Apparently, the error occurs if the upload field is left empty or a previous image is deleted. @Umbraco.GetMediaUrl should know how to handle this situation, because the page won't compile as it is right now. The workaround is and if statement or similar that checks if the Upload field has something in it before callind @Umbraco.GetMediaUrl. Any ideas on what kind of statement could I use?
Umbraco 5: Render image from Upload in child
I'm cycling through the children of the current page, and I want to render an image (type upload with alias myImage), and some text (type textarea with alias myText). Currently I have this:
@foreach (var item in DynamicModel.Children)
{
<div class="product">
<img src="@item.myImage" alt="Photo of @item.Name" />
<h2>@item.Name</h2>
<p>@item.myText</p>
</div>
}
But when I visit the page, the image is not rendered and the alt attribute is shown. All other fields work as expected. I'm using Umbraco 5 RTM build 5.0.310.16
Ok, so I've got this working:
@inherits RenderViewPage
@using System.Web.Mvc.Html
@using Umbraco.Cms.Web;
@using Umbraco.Framework;
@foreach (var item in DynamicModel.Children)
{
<div class="product">
<img src="@Umbraco.GetMediaUrl(item.Id, "myImage")" alt="Photo of @item.Name" />
<h3>@item.Name</h3>
<p>@item.myText</p>
</div>
}
So for anyone wondering how to get an image from and Upload property, the sintax is @Umbraco.GetMediaUrl(page.Id, "propertyAlias")
The problem is that now this is not working for every case. In a level 3 page I can get the image from the children at level 4. However, in another page at level 2, I cannot get images from children in level 3. I get this error (my translation) "Not valid URL: cannot analyze hostname" System.UriFormatException appears in the details. Any ideas?
Apparently, the error occurs if the upload field is left empty or a previous image is deleted. @Umbraco.GetMediaUrl should know how to handle this situation, because the page won't compile as it is right now. The workaround is and if statement or similar that checks if the Upload field has something in it before callind @Umbraco.GetMediaUrl. Any ideas on what kind of statement could I use?
I have the same issue as Eduardos last post...
Any ideas?
is working on a reply...