Try our conversational search powered by Generative AI!

EPiServer.Core.XhtmlString error

Vote:
 

I want to have a XHTMLString property so that the editors can edit the text as they want. I have tried with and without the attribute [UIHint(UIHint.LongString)] and it causes the same error:

Unable to cast object of type 'System.String' to type 'EPiServer.Core.XhtmlString'.

the code, HTML and EPiServer property:

@Model.CurrentPage.Text
 [Display(
           GroupName = SystemTabNames.Content,
           Name = "Text",
           Description = "The text",
           Order = 1)]
[UIHint(UIHint.LongString)]
public virtual XhtmlString Text { get; set;}


What am I missing? I'm using EPiServer 7

#147337
Apr 12, 2016 14:20
Venkat - May 22, 2023 15:51
I am also facing the same error, Here i am trying to change the property type from xhtmlstring to string type. When i am changing the type of the property, am getting the below error.
InvalidCastException: Unable to cast object of type 'EPiServer.Core.XhtmlString' to type 'System.String'

I removed the text from the property in edit mode but still am getting the same error. Please let me know the suitable solution for this.
i am using Episerver 12
Vote:
 

Hi,

You don't need the UI hint. The error states that you cannot convert a string to XhtmlString. Are you trying to set the value of the property Text somewhere in your code? E.g.:

currentPage.Text = "a text";
#147353
Apr 12, 2016 19:36
Vote:
 

Im guessing that the property used to be a regular string and some text was added to that property in edit mode making it invalid for xhtmlstring.

Remove the text from the property in edit mode and if needed remove the property from the pagetype from admin mode, then rebuild and try again.

#147392
Apr 13, 2016 14:39
Vote:
 
<p>Yes :)! thank you the db didn't know what to take so it snapped. Cleaning everything out first did the trick! Thanx!</p>
#147394
Apr 13, 2016 14:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.