Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello guys ,
I do get error message when I try to do If equal then .. CS0029: Cannot implicitly convert type 'int' to 'System.Web.IHtmlString'
Code:
var test = @Umbraco.Field("test"); @if (test = 1 ){ ..... } else { .... }
In backoffice is used Umbraco.Decimal editor for that test property.
Could someone help to make it work ?
Thank you
Hi,
Umbraco.Field always returns IHtmlString.
If you want a typed version you will want either Model.Content.GetPropertyValue
Or
Model.GetPropertyValue
You will want the first one if you view inherits UmbracoTemplatePage and the Second is for UmbracoViewPage
Matt
Used first option,
now Im getting Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?)
To do a compare in not an assignment you need to use == in the if
Hi again,
Tried , but then im left with CS0019: Operator '==' cannot be applied to operands of type 'object' and 'int'
Could you show me the code as it is now :)
@{ var test = Model.Content.GetPropertyValue
Am on my phone so can't indent but that should work
var test = Model.Content.GetPropertyValue("test"); @if (test == 1 ){
GetPropertyValue("test"); Should be
GetPropertyValue<int>("test");
Thank you , It is working now , I just did not know how to specify it as a INT Have a great day Thanks
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
CS0029: Cannot implicitly convert type 'int' to 'System.Web.IHtmlString'
Hello guys ,
I do get error message when I try to do If equal then ..
CS0029: Cannot implicitly convert type 'int' to 'System.Web.IHtmlString'
Code:
In backoffice is used Umbraco.Decimal editor for that test property.
Could someone help to make it work ?
Thank you
Hi,
Umbraco.Field always returns IHtmlString.
If you want a typed version you will want either Model.Content.GetPropertyValue
Or
Model.GetPropertyValue
You will want the first one if you view inherits UmbracoTemplatePage and the Second is for UmbracoViewPage
Matt
Used first option,
now Im getting Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?)
To do a compare in not an assignment you need to use == in the if
Hi again,
Tried , but then im left with CS0019: Operator '==' cannot be applied to operands of type 'object' and 'int'
Could you show me the code as it is now :)
@{ var test = Model.Content.GetPropertyValue
Am on my phone so can't indent but that should work
GetPropertyValue("test"); Should be
Thank you , It is working now , I just did not know how to specify it as a INT Have a great day Thanks
is working on a reply...