After creating a region object with a single property attached to my page like the following:
[PageType(Title = "Start page")]
[PageTypeRoute(Title = "Default", Route = "/start")]
public class StartPage : Page<StartPage>
{
[Region]
public Footer Footer { get; set; }
}
public class Footer
{
[Field]
public StringField FooterText{ get; set; }
}
And when the database table for _PostField is empty I can run the application and edit the FooterText, but as I soon as preview the page I get the following error:
An unhandled exception occurred while processing the request.
ArgumentException: Object of type 'Piranha.Extend.Fields.StringField' cannot be converted to type 'Cms.Models.Regions.Footer'.
System.RuntimeType.TryChangeType(object value, Binder binder, CultureInfo culture, bool needsSpecialCast)
The error makes sense as it saved as Piranha.Extend.Fields.StringField in the database. I guess it should be saved as Cms.Models.Regions.Footer.FooterText..
Am I missing something obvious?
Hi!
At the moment, a region cannot contain a single field.
So in your case, you could edit your StartPage to look like this:
[PageType(Title = "Start page")]
[PageTypeRoute(Title = "Default", Route = "/start")]
public class StartPage : Page<StartPage>
{
[Region]
public StringField Footer { get; set; }
}
More information about this can be find here under the Single Field Regions section.
BR
Filip
So by adding another propertie the error will go away.. Alright it did the job and I can see it clearly now in the documentation.
Thanks!
Most helpful comment
Hi!
At the moment, a region cannot contain a single field.
So in your case, you could edit your
StartPageto look like this:More information about this can be find here under the Single Field Regions section.
BR
Filip