SaaS CMS has officially launched! Learn more now.

MVC Dynamic Property question


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?



Feb 06, 2013 16:07

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:

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

Feb 06, 2013 17:39

Thanks, it is exactly what I was looking for.

Feb 06, 2013 21:22

I have used this logic in my 7.5 solution and and getting a null when trying to access the dynamic property

        public virtual PageReference SiteConfigurationPage { get; set; }

While debugging i get the following

    base: {9}
    RemoteSite: null


Any idea on what i might be doing wrong ?

Sep 16, 2014 18:41

In CMS 7.5 to achieve the same functionality you need to implement the dynamic property like this: 

public virtual string DynamicPropertyName
                var dynamicProp = Property["DynamicPropertyName"];
                return dynamicProp != null ? dynamicProp.Value as string : null;
Edited, Sep 17, 2014 17:06

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 : 


public virtual string SiteConfigurationPage

{ get

   { var configPage = Property["SiteConfigurationPage"];

       return configPage != null ? configPage.Value as string : null; }


but same error..

Any ideas?

Oct 13, 2014 17:00

Komal, make sure the name of the property you created via admin mode and the magic string in code are the same,

Oct 13, 2014 17:03

Worked!!  Thanks minesh..

Oct 13, 2014 17:37
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.