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
I have a blob of code, that works fine and looks to be standar razor code... But when using this within a typedContext context it fails
The working code outside of the TypedContent is this :
if (@fieldset.HasValue("youtube")) { string myString = @fieldset.GetValue("youtube"); int charPositionStart = myString.IndexOf("="); int lengthOfText = 11; myString = myString.Substring(charPositionStart+1, lengthOfText); var myBg = "http://img.youtube.com/vi/" + @myString + "/maxresdefault.jpg"; ---- HTML stuff ---- }
if (@boxItem.HasValue("youtube")) { string myString = @boxItem.GetPropertyValue("youtube"); int charPositionStart = myString.IndexOf("="); int lengthOfText = 11; myString = myString.Substring(charPositionStart+1, lengthOfText); var myBg = "http://img.youtube.com/vi/" + @myString + "/maxresdefault.jpg"; ---- HTML stuff ----- }
Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
on this line:
string myString = @boxItem.GetPropertyValue("youtube");
Hi Claus,
What if you do something like this
var myString = @boxItem.GetPropertyValue<string>("youtube");
Does this help, or did you get same error.
/Dennis
Either make the variable implicit
var myString = boxItem.GetPropertyValue("youtube");
Or specify the return type
string myString = boxItem.GetPropertyValue<string>("youtube");
Jeavon
Or both as Dennis has suggested :)
Also you don't need/want those @ in there
did the trick, thanks guys
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Syntax difference when content is "TypedContent"
I have a blob of code, that works fine and looks to be standar razor code... But when using this within a typedContext context it fails
The working code outside of the TypedContent is this :
if (@fieldset.HasValue("youtube")) { string myString = @fieldset.GetValue("youtube"); int charPositionStart = myString.IndexOf("="); int lengthOfText = 11; myString = myString.Substring(charPositionStart+1, lengthOfText); var myBg = "http://img.youtube.com/vi/" + @myString + "/maxresdefault.jpg"; ---- HTML stuff ---- }
Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
on this line:
Hi Claus,
What if you do something like this
Does this help, or did you get same error.
/Dennis
Hi Claus,
Either make the variable implicit
Or specify the return type
Jeavon
Or both as Dennis has suggested :)
Also you don't need/want those @ in there
did the trick, thanks guys
is working on a reply...