Umbraco 8... What am I doing wrong?!?!?! The IF line works now but the lines that follow fail... I can not figure out what is happening. Everything I read says
Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'
Source Error:
Line 41: {
Line 42: <div class="nav-link--home">
Line 43: <img class="logo-image" src="@homePg.Value<IPublishedContent>("siteLogo").Url()" >
Line 44: </div>
Line 45: }
And not error out but the IMG tag can not. I tryed many options for the IF statement until I finally got that working so I thought I had the solution but that solution did not fix the IMG tag. It makes no sense to me!
The siteLogo property could be of type (if allow multiple is selected)<IEnumerable<IPublishedContent>>, this is a group / list of IPublishedContent, so you need to return the first one, see below:
var logoUrl = homePg.Value<IEnumerable<IPublishedContent>>("siteLogo").FirstOrDefault()?.Url;
Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'
Line 41: {
Line 42: <div class="nav-link--home">
Line 43: <img class="logo-image" src="@homePg.Value<IEnumerable<IPublishedContent>>("siteLogo").FirstOrDefault()?.Url" >
Line 44: </div>
Line 45: }
The problem is you needed brackets around your code when you retrieve the logo url, as the razor rendering engine was assuming the first " was the close of the src.
Because they are Not the same and I can't figure out how to take a code snippet from one page type and use it in a different page type... I don't know why there is not some helper conversion for this?!?!?!?! Accessing them should be some how consistent from each type in my opinion.
If I had a mapping equivalent, for Umbraco 8 it would prevent MANY grey hairs!!! It would need to include examples of both Root as well as CurrentPage Models.
Umbraco 8 Root Site Logo URL issues....
Umbraco 8... What am I doing wrong?!?!?! The IF line works now but the lines that follow fail... I can not figure out what is happening. Everything I read says
How do I do that from Root?
var home = Model.Content.Root(); var homePg = (HomePage)Model.Content.Root();
Neither work the only one that compiled with the IF statement was
This FAILS:
WHY???? I still can not fix the line:
Error:
Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'
Source Error:
Partial Macro View:
In Umbraco 8 .Content has been removed.
So your code should be:
then
and to output the CSS class would be:
No there is more code in the file that is just the section that errors. The homepageSelected is used in a different context.
I just realized it did not post correctly.
Here is the issue: The below line fails:
Error: Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'
This works however:
I don't understand why the IF statement can use:
And not error out but the IMG tag can not. I tryed many options for the IF statement until I finally got that working so I thought I had the solution but that solution did not fix the IMG tag. It makes no sense to me!
The siteLogo property could be of type (if allow multiple is selected)
<IEnumerable<IPublishedContent>>
, this is a group / list of IPublishedContent, so you need to return the first one, see below:The Line still errors with the SAME error:
Compiler Error Message: CS1503: Argument 1: cannot convert from 'method group' to 'object'
Also what is the equivalent of:
To:
Ok, the issue is you are using a PartialViewPageMacro... which works differently to UmbracoViewPage.
The problem is you needed brackets around your code when you retrieve the logo url, as the razor rendering engine was assuming the first " was the close of the src.
That finally worked. Umbraco 8 is killing me I don't understand why everything is accessed different.
I think I would save years of many developers life if someone could document just one simple page:
How to access the Root OR the actual CurrentPage Model properties... i.e.
FROM each of these:
Because they are Not the same and I can't figure out how to take a code snippet from one page type and use it in a different page type... I don't know why there is not some helper conversion for this?!?!?!?! Accessing them should be some how consistent from each type in my opinion.
If I had a mapping equivalent, for Umbraco 8 it would prevent MANY grey hairs!!! It would need to include examples of both Root as well as CurrentPage Models.
Whoever could document that would be pure genius!
Roger Newmon,
Thanks very much! Your digging into this really helped me with my issue:
BEFORE (threw errors):
@(Model.Value("SiteLogo").Url)
AFTER (works perfectly):
@(Model.Value<IPublishedContent>("SiteLogo").Url)
Thank you again! After inserting <IPublishedContent> after "Model.Value", everything worked for me.
is working on a reply...