title: Exception in Glass mapper for Sitecore in PageEditor mode
body: <p>For the code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>strMenuText.Append(RenderLink(mainlinkitem, 
          x =&gt; x.NavigationItem.Url.StringToLink(), 
          isEditable: true,            
          contents: mainlinkitem.NavigationTitle));
  </code></pre>
  
  <p>Here <code>mainlinkitem</code> is Navigation object for interface created for data template.
  I am using interfaces in this case and castle windsor creates dynamic proxy objects for this.</p>
  
  <p>Things work ok until I try to use Page editor mode and below error shows up from glass mapper api.</p>
  
  <blockquote>
    <p>Expression doesn't evaluate to a member
    x.NavigationItem.Url.StringToLink() at
    Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression<code>1 field,
    Expression</code>1 standardOutput, T model, String parameters, Context
    context, Database database, TextWriter writer)</p>
  </blockquote>
  
  <p>Note: StringToLink is extension method for converting external url in <code>string</code> form to Glass mapper <code>Glass.Mapper.Sc.Fields.Link</code> type.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static Link StringToLink(this string urlvalue)
  {
      Link itemLink = new Link();
      itemLink.Url = urlvalue;
      return itemLink;
  }
  </code></pre>
  
  <h2>UPDATE</h2>
  
  <p>Code for menu user control:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class MenuControl : GlassUserControl&lt;INavigationFolder&gt;
  {
      protected override void GetModel()
      {
          base.GetModel();
  
          SiteLevelSettings siteSettings = SitecoreContext.GetItem&lt;SiteLevelSettings&gt;(Guid.Parse("Some GUID"));
          Model = siteSettings.HeaderMenuFolder;
      }
  
      protected void Page_Load()
      {
          if (!Page.IsPostBack)
          {
              LoadMenu();
          }
      }
  
      private void LoadMenu()
      {
          StringBuilder strMenuText = new StringBuilder();
  
          foreach (INavigationLink mainlinkitem in Model.ChildLinks)
          {
              if (CanRead(mainlinkitem))
              {
                  strMenuText.Append("&lt;td class='menu-item'&gt;");
                  if (mainlinkitem.ChildLinks != null &amp;&amp; mainlinkitem.ChildLinks.Count() &gt; 0)
                  {
                      strMenuText.Append("&lt;ul&gt;");
                      foreach (INavigationLink linkitem in mainlinkitem.ChildLinks)
                      {
                          if (CanRead(linkitem))
                          {
                              strMenuText.Append("&lt;li&gt;");
                              if (linkitem.NavigationItem != null)
                              {
                                  strMenuText.Append(RenderLink(linkitem, x =&gt; x.NavigationItem.Url.StringToLink(), isEditable: false, contents: linkitem.NavigationTitle));
                              }
                              else if (linkitem.NavigationGeneralLink != null)
                              {
                                  strMenuText.Append(RenderLink(linkitem, x =&gt; x.NavigationGeneralLink, isEditable: false, contents: linkitem.NavigationTitle));
                              }
                              strMenuText.Append("&lt;/li&gt;");
                          }
                      }
  
                      strMenuText.Append("&lt;/ul&gt;");
                  }
                  strMenuText.Append("&lt;div class='nav-divider'&gt;");
                  if (mainlinkitem.NavigationItem != null)
                  {
                      strMenuText.Append(RenderLink(mainlinkitem, x =&gt; x.NavigationItem.Url.StringToLink(), isEditable: false, contents: mainlinkitem.NavigationTitle));
                  }
                  else if (mainlinkitem.NavigationGeneralLink != null)
                  {
                      strMenuText.Append(RenderLink(mainlinkitem, x =&gt; x.NavigationGeneralLink, isEditable: true, contents: mainlinkitem.NavigationTitle));
                  }
                  strMenuText.Append("&lt;/div&gt;&lt;/td&gt;");
              }
          }
  
          ltrMenu.Text = strMenuText.ToString();
      }
  
      private bool CanRead(IItem mainlinkitem)
      {
          var ItemId = mainlinkitem.TemplateId;
          var ItemIDObj = new Sitecore.Data.ID(ItemId);
          var contentdatabase = Sitecore.Context.Database;
          var item = contentdatabase.GetItem(ItemIDObj);
          return item.Access.CanRead();
      }
  }
  </code></pre>
  
  <p>Navigation Folder interface for glass mapper:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[SitecoreType(TemplateId = "{Some GUID}")]
  public interface INavigationFolder : IItem
  {
      [SitecoreChildren(IsLazy = false)]
      IEnumerable&lt;INavigationLink&gt; ChildLinks { get; set; }
  }
  </code></pre>
  
  <p>Navigation Link interface for glass mapper:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[SitecoreType(TemplateId = "{Some GUID}")]
  public interface INavigationLink : IItem
  {
      [SitecoreField(FieldId = "{Some GUID}")]
      string NavigationTitle { get; set; }
  
      [SitecoreField(FieldId = "{Some GUID}")]
      IItem NavigationItem { get; set; }
  
      [SitecoreField(FieldId = "{Some GUID}")]
      Link NavigationGeneralLink { get; set; }
  
      [SitecoreField(FieldId = "{Some GUID}")]
      string ShortDescription { get; set; }
  
      [SitecoreChildren(IsLazy = false)]
      IEnumerable&lt;INavigationLink&gt; ChildLinks { get; set; }
  
  }
  </code></pre>
  
  <p>Note: This will code will generate menu similar to sitecore site</p>
  
  <h2>UPDATE</h2>
  
  <p>Url property in interface <code>IItem</code> is defined as follows:</p>
  
  <pre><code>[SitecoreType(TemplateId = "{Some GUID}")]
  public interface IItem
  {
      [SitecoreId()]
      Guid ID { get; }
  
      [SitecoreInfo(Type = SitecoreInfoType.Language)]
      Language Language { get; }
  
      [SitecoreInfo(Type = SitecoreInfoType.Version)]
      int Version { get; }
  
      [SitecoreInfo(Type = SitecoreInfoType.Url)]
      string Url { get; }
  
      [SitecoreInfo(Type = SitecoreInfoType.TemplateId)]
      Guid TemplateId { get; }
  
      [SitecoreInfo(Type = SitecoreInfoType.Key)]
      string Key { get; }
  }
  </code></pre>