Hi,
I am trying to get the value(s) of an image in a partial view. I am trying to get the image url.
I can get the other page elements like title, description but not the image.
It is created using imageCropper.
Here is the error:
System.ArgumentException: 'The value "Umbraco.Web.PublishedModels.ImageBanner" is not of type "Umbraco.Web.PublishedModels.Image" and cannot be used in this generic collection.
Parameter name: value'
here is my code for looping through the banners on our site:
ISiteService SiteService = Current.Factory.GetInstance<ISiteService>();
IPublishedContent banner_list = SiteService.GetContentUsingAlias("bannerSettings");
if (banner_list.ContentType.Alias == "bannerSettings")
{
foreach (var item in banner_list.Children())
{
var a = item.GetProperty("bannerTitle").Value();
var b = item.GetProperty("bannerDescription").Value();
var c = item.GetProperty("bannerImage").Value();
}
We are adapting code from our Umbraco 7 website. This is what works in Umbraco 7, but not in Umbraco 8:
var banner_list = new DynamicNode(-1).DescendantsOrSelf("bannerSettings").First();
var bobj = new Dictionary<string, Dictionary<string, string>>();
if (banner_list.NodeTypeAlias == "bannerSettings")
{
foreach (var item in banner_list.Children.Select((val, i) => new { i, val }))
{
var banners = new Dictionary<string, string>();
foreach (var ite in item.val.PropertiesAsList)
{
banners.Add(ite.Alias, (ite.Value.Contains("umb://") ? Umbraco.TypedMedia(ite.Value).Url : ite.Value));
}
bobj.Add(item.val.Name.ToLower().Replace(" ", ""), banners);
}
}
}
Hi all,
Just solved the above question, in a way.
I changed the banner image to a normal image (out of the box, so to say) in the media section. I had created my own folder type and media picker.
Now, using the following I can get the image properties etc.
var c = item.GetProperty("bannerImage").Value<IPublishedContent>();
var d = c.Url;
I think it would be handy if someone came up with a solution for the original error when I created a new ImageCropper and media Picker.
Cannot get the image path or any other value
Hi, I am trying to get the value(s) of an image in a partial view. I am trying to get the image url. I can get the other page elements like title, description but not the image. It is created using imageCropper.
Here is the error: System.ArgumentException: 'The value "Umbraco.Web.PublishedModels.ImageBanner" is not of type "Umbraco.Web.PublishedModels.Image" and cannot be used in this generic collection. Parameter name: value'
here is my code for looping through the banners on our site:
We are adapting code from our Umbraco 7 website. This is what works in Umbraco 7, but not in Umbraco 8:
Any help would be terrific here. Thank you.
Pete
Hi all, Just solved the above question, in a way. I changed the banner image to a normal image (out of the box, so to say) in the media section. I had created my own folder type and media picker.
Now, using the following I can get the image properties etc.
I think it would be handy if someone came up with a solution for the original error when I created a new ImageCropper and media Picker.
Thank you
is working on a reply...