Thursday, May 21, 2015

EpiServer - Get Typed PageData Object In Repeater



In the view we have for example:

 <h3><%# Container.GetDataItem<CallPage>().Heading %></h3>  

Then just Create a Extension method to get the correct type above something like this:


 public static T GetDataItem<T>(this RepeaterItem container)  
 {  
      If Satsen vet jag inte om den fungerar.  
      if (container.GetType().IsAssignableFrom(typeof (T)))  
      {  
       //Some Error handling?  
      }  
       return (T)container.DataItem;  
 }  

No comments:

Post a Comment