You can have dynamic properties as typed properties on your model. You should then mark them with Ignore atttribute otherwise it will be created a page property with same name. Like below:
[Ignore]
public virtual XhtmlString DynamicHtml { get; set; }
It is however not possible to create/define dynamic properites on your models so you need to create them in admin mode. Then in your view you can render them as :
Html.DisplayFor(m => m.DynamicHtml)
Note: you will not get onpageedit support on your dynamic properties, the need to be edited in the separeate dynamic properties dialog
I have used this logic in my 7.5 solution and and getting a null when trying to access the dynamic property
[Ignore]
public virtual PageReference SiteConfigurationPage { get; set; }
While debugging i get the following
Model.CurrentPage["SiteConfigurationPage"]
{9}
base: {9}
RemoteSite: null
Model.CurrentPage.SiteConfigurationPage
null
Any idea on what i might be doing wrong ?
In CMS 7.5 to achieve the same functionality you need to implement the dynamic property like this:
[Ignore]
public virtual string DynamicPropertyName
{
get
{
var dynamicProp = Property["DynamicPropertyName"];
return dynamicProp != null ? dynamicProp.Value as string : null;
}
}
I have created Dynamic Property in Admin mode but following code always written null reference exception in EPIserver7.5.
PropertyData property = CurrentPage.Property["SiteConfigurationPage"];
Even i also tried with your solution :
[Ignore]
public virtual string SiteConfigurationPage
{ get
{ var configPage = Property["SiteConfigurationPage"];
return configPage != null ? configPage.Value as string : null; }
}
but same error..
Any ideas?
Komal, make sure the name of the property you created via admin mode and the magic string in code are the same,
I'm starting a new project with version 7, and we are trying to follow ideas presented in the Alloy Tech demo site(MVC and Razor mostly). However the Alloy site does not use Dynamic Properties, at least as far I can see. What is the best way to access these properties with Razor?
How would we access Dynamic Properties if the Model does not have knowledge of it? Should we define these properties in the Model as well?
Thanks.