Default property type mappings in Page Type Builder

If you don't specify what type of EPiServer property a code property should map to using the Type property on the PageTypeProperty attribute Page Type Builder will try to figure it out for you. The default mappings are as follows:

Code property type Default Page Type Property Type
string PropertyXhtmlString
int PropertyNumber
int? PropertyNumber
bool PropertyBoolean
bool? PropertyBoolean
DateTime PropertyDate
DateTime? PropertyDate
float PropertyFloatNumber
float? PropertyFloatNumber
PageReference PropertyPageReference
PageType PropertyPageType

 

That is, if you create a couple of properties with code such as this:

[PageTypeProperty]
public virtual string MainBody { get; set; }

[PageTypeProperty]
public virtual PageReference LinkTo { get; set; }

[PageTypeProperty]
public virtual bool IncludeInRssFeed { get; set; }

It’s equivalent to writing the code this way:

[PageTypeProperty(Type= typeof(PropertyXhtmlString))]
public virtual string MainBody { get; set; }

[PageTypeProperty(Type = typeof(PropertyPageReference))]
public virtual PageReference LinkTo { get; set; }

[PageTypeProperty(Type = typeof(PropertyBoolean))]
public virtual bool IncludeInRssFeed { get; set; }

If you on the other hand where to create a property of a type that isn’t included in the default mapped types in the table above and you don’t specify the Type property of the attribute, such as this:

[PageTypeProperty]
public virtual Uri LinkUri { get; set; }
You’ll get an error message like the one below at runtime.

ErrorMessage

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Comments

  1. Alan Allard's avatar

    Alan Allard 1 years ago

    And what about if you don't rely on defaults and define the type as, say, "PropertyMultipleValue" and still get the same error message? Are multiple value lists not handled at present?

  2. Alan Allard's avatar

    Alan Allard 1 years ago

    What happens is that you define PropertyAppSettingsMultiple instead :) Sorry for the noise...feel free to delete ;)

  3. Tomas Larsson's avatar

    Tomas Larsson 1 years ago

    How do i get rid of the html editor for strings? I just want a text input field!

  4. Emil Lundin's avatar

    Emil Lundin 1 years ago

    Tomas, just add a string property and decorate it with [PageTypeProperty(Type = typeof(PropertyString))]

Follow me on Twitter

  1. @chraas You might want to use it for complex parts of the site and not use it for simple rendering pages. 2 days ago
  2. @chraas In theory more SOLID, but I'm not sure it's worth the price. 2 days ago
  3. @chraas Be warned that you're introducing one big chunk of complexity with EPiMVP :) 2 days ago
follow me

Latest comments

  1. Berra S wrote "Read your post at http://joelabrahamsson.com/entry/using-xfo..." on PageData objects not returned as typed when using Page Type Builder and FindPagesWithCriteria
  2. Linus wrote "1 up for behaviour being as close as expected as possible!" on A common problem with Page Type Builder and UniqueValuePerLanguage set to false
  3. Joel Abrahamsson wrote "Hi Hans, Could it be that you previously didn't have Page..." on Page Type Builder 2.0 released

About this site

This blog is built with EPiServer Community, EPiServer CMS, ASP.NET MVC and a bunch of other great products. The source code is available for download at the projects page, where you also can read more about this site and my other projects.

read more