Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EpiServer: Convert String to XHTMLString

I'm currently using EpiServer 7.5 with ASP.Net MVC.

Basically, I'm defining a property inside a model which needs to be of type XHtmlString. What I wish to do inside the model is set a default value for the XHtmlString, but since this is represented by a string, how can I do this?

Here's an example in code - this is my model:

[Required]
[Display(
    Name = "Thank you message",
    Order = 1)]
public virtual XhtmlString ThankYouMessage{ get; set; }

Now, later on the code, I simply want to set the default value of this ThankYouMessage type to a string.

ThankYouMessage = "Default thank you message";

This won't work because ThankYouMessage is an object type of XHtmlString and I obviously can't set this to a type of string.

I think it has something to do with the XHtmlStringConverter but I can't figure this out - any help would be appreciated.

Cheers!

like image 557
user3556163 Avatar asked Feb 11 '23 04:02

user3556163


1 Answers

You'll need to convert the string into an XhtmlString as that is the property type. This is simply done by creating a new XhtmlString object.

   ThankYouMessage  = new XhtmlString("Default thank you message")
like image 129
jskzyb Avatar answered Feb 13 '23 19:02

jskzyb