i want to modify the ContentPageBase, in a functional site, i tried to add a property called for example (weight), but if there is an existing page in the database, the site will malfunction, and throws an Exception, of (Object reference not set to an instance of an object).
how can i correct the already entered data ?
public abstract class ContentPageBase : PageBase, ICommentable
{
[EditableTextBox("Weight", 10, ContainerName = Tabs.Details)]
//newly added property.
public virtual int Weight
{
get { return (int)GetDetail("Weight"); }
set { SetDetail("Weight",开发者_StackOverflow value); }
}
}
Yes you get a null refernce when accessing the property and no data exists in DB.
The getter in the old N2CMS must be
get { return (int)(GetDetail("Weight") ?? 0); }
If you want 0 as default of course.
Best regard
i figured out how to solve this, just drop the Getters and Setters of the property and use it like this:
public virtual int Weight { get; set;}
this is new feature in N2Cms 2.0.
and when you give a new value to the newly-added property, N2cms add a new record the N2Detail table for the page.
精彩评论