EpiServer: convert string to XHTMLString

I am currently using EpiServer 7.5 with ASP.Net MVC.

Basically, I am defining a property inside the model that should be of type XHtmlString. What I want to do inside the model is the default for the XHtmlString, but since this is represented by a string, how can I do this?

Here's some sample code - this is my model:

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

      

Now, later in the code, I just want to set the default of this type ThankYouMessage to string.

ThankYouMessage = "Default thank you message";

      

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

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

Hooray!

+3


source to share


1 answer


You will need to convert the string to XhtmlString as this is the type of the property. This is simply done by creating a new XhtmlString object.



   ThankYouMessage  = new XhtmlString("Default thank you message")

      

+5


source







All Articles