How can I render a class object as property in a pagedata model?

Vote:
 

Hi ,

I have a simple class as:

public class TestPage1

{

               public virtual string Page1PropertyA { get; set;}

               public virtual string Page1PropertyB { get; set;}    

}

Now I want to use this as a property in a pagedata class, I use it as below:-

public class MyPage: PageData

{

[CultureSpecific]              

public virtual TestPage1 TestPageProperty { get; set; } // (or any object you prefer)

 }          

I also created a base custom property for the same:-

[PropertydefinationtypePlugin]

public class PageObjectProperty : Property
{
string outputAsJson;
public PageObjectProperty()
{
_objectSerializer = this._objectSerializerFactory.Service.GetSerializer("application/json");
//outputAsJson = JsonConvert.SerializeObject(T);
}

private Injected _objectSerializerFactory;

private IObjectSerializer _objectSerializer;

public override PropertyData ParseToObject(string value)
{
ParseToSelf(value);
return this;
}

}

But i am not getting the class object with all its properties render in edit mode ? iHow can I achieve the same.

It works when i use PropertyList<> and create class object list, but not for single object instance.

Kindly help

#186570
Dec 22, 2017 13:51
Vote:
 

Blocks can be used as both blocks in pages and shared within page content. You'd be best changing TestPage1 to inherit from block and that will render those groups of items in page. You'll then be able to use the standard properties

#186571
Dec 22, 2017 13:58
Vote:
 

Example https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Content/Properties/using-a-block-as-a-property/

#186572
Dec 22, 2017 13:59
Vote:
 

Hi Scott,

We dont want to use Block in this case as the class are specific object model which will merged to form a main Pagedata model. As there are large number of properties, so  we are divinding it into specific class object model.

//ashish

#186573
Dec 22, 2017 14:04
Vote:
 

Hi Ashish.

I would agree with Scott - it does look somewhat strange to create a property, containing multiple properties, with Name included in it's classname. Not sure I fully understand the rationale behind not creating a shared block model, but maybe it would be more beneficial for you to create an abstract PageType containing these shared properties, which all your relevant PageTypes then inherit from. Your example looks like a another way of achieving inheritance.

If you don't find inheritance beneficial, because of some misunderstood point on my end, do you then mind sharing your controller and view, which is what takes care of the rendering for both end-users and editors. Then we can help you with your current direction of implementation.

/Casper Aagaard Rasmussen

 

#186578
Edited, Dec 22, 2017 15:45
Vote:
 

There are basically 3 options which can be combined 

  1. Interfaces 
  2. Local blocks 
  3. Inheritance 

1 and 2 is more relevant for a "has a" relation. Article page has SEO information.

3 is the way to go for "is a" relationship. BicycleProductPage is a ProductPage. 

By using standard OOP principles like interfaces you'll be able to simplify and generalize logic in controllers and services.

#186583
Dec 23, 2017 9:00
Vote:
 

Thanks all, I guess my original option was not feasible here, I will create block model as a property for the same as Scott adviced.

Thanks all for the replies :)

//ashish

#186596
Dec 26, 2017 8:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.