title: Member Expression cannot convert to object from nullable decimal
body: <p>I am working on an MVC project and would like to pass the Html.TextboxFor method the name of a property.  This is my viewmodel </p>
  
  <pre><code>public class RuleViewModel&lt;T&gt; where T : class, IValidatableObject
  {
      private T _rule;
      public T RuleModel
      {
          get
          {
              return _rule
                  ?? (_rule = Activator.CreateInstance&lt;T&gt;());
          }
      }
  
      public RuleMetadata Metadata { get; set; }
  
      public Expression&lt;Func&lt;RuleViewModel&lt;T&gt;, Object&gt;&gt; GetParameterByName(PropertyInfo pi)
      {
          var fieldName = Expression.Parameter(typeof(RuleViewModel&lt;T&gt;), "x");
          var fieldExpression = Expression.PropertyOrField(Expression.Property(fieldName, "RuleModel"), pi.Name);
          var exp = Expression.Lambda&lt;Func&lt;RuleViewModel&lt;T&gt;, Object&gt;&gt;(fieldExpression, fieldName);
          return exp;
      }
  
  }
  </code></pre>
  
  <p>Then in the view I do this</p>
  
  <pre><code>  @foreach (var prop in Model.RuleModel.GetType().GetProperties())
      {
          var result = Model.Metadata.Columns.SingleOrDefault(m =&gt; m.ColumnName == prop.Name);
          if (result != null)
          {
              &lt;td&gt;
                  @Html.TextBoxFor(Model.GetParameterByName(prop))
              &lt;/td&gt;
          }
      }
  </code></pre>
  
  <p>The problem is that when the property is of type decimal?, I get a cannot convert nullable decimal to object error.  I looked around and found that you can use Expression.Convert to fix this but when I do that I get an error on the view </p>
  
  <p>Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions. </p>
  
  <p>Any help would be appreciated.  This is a proof of concept project that I'm working on and without this piece it is dead in the water.</p>