title: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions
body: <p>My model:</p>
  
  <pre><code>public class EmployeeModel
  {
      [Required]
      [StringLength(50)]
      [Display(Name = "Employee Name")]
      public string EmpName { get; set; }
  
      [Required]
      [StringLength(150)]
      [Display(Name = "Email Id")]
      public string Email { get; set; }
  
      [Required]
      [Range(18, 150)]
      public int Age { get; set; }
  
  }
  </code></pre>
  
  <p>In my view: </p>
  
  <pre><code> @Html.MyEditFor(model=&gt;model.EmpName)
   @Html.MyEditFor(model=&gt;model.Email)
   @Html.MyEditFor(model=&gt;model.Age)
  </code></pre>
  
  <p>My custom helper:</p>
  
  <pre><code>public static MvcHtmlString MyEditFor&lt;TModel&gt;(this HtmlHelper&lt;TModel&gt; html, Expression&lt;Func&lt;TModel, object&gt;&gt; expression)
      {
          var partial = html.Partial("Item", new LabelEditorValidation() { Label = html.LabelFor(expression), Editor = html.EditorFor(expression), Validation = html.ValidationMessageFor(expression) }).ToString();
          return MvcHtmlString.Create(partial);
      }
  </code></pre>
  
  <p>Item.cshtml - partial view:</p>
  
  <pre><code> @model MyClientCustomValidation.Models.LabelEditorValidation 
          &lt;tr&gt;
              &lt;td class="editor-label" style="border: 0;"&gt;
                  @Model.Label
              &lt;/td&gt;
              &lt;td class="editor-field" style="border: 0"&gt;
                  @Model.Editor
                  @Model.Validation
              &lt;/td&gt;
          &lt;/tr&gt;
  </code></pre>
  
  <p>LabelEditorValidation - model for Item.cshtml:</p>
  
  <pre><code>      public class LabelEditorValidation
  {
      public MvcHtmlString Validation { get; set; }
      public MvcHtmlString Label { get; set; }
      public MvcHtmlString Editor { get; set; }
  }
  </code></pre>
  
  <p>I have exception </p>
  
  <blockquote>
    <p>Templates can be used only with field access, property access,
    single-dimension array index, or single-parameter custom indexer
    expressions</p>
  </blockquote>
  
  <p>on line:</p>
  
  <pre><code>    var partial = html.Partial("Item", new LabelEditorValidation() { Label = html.LabelFor(expression), Editor = html.EditorFor(expression), Validation = html.ValidationMessageFor(expression) }).ToString();
  </code></pre>
  
  <p>The exception occures when   <code>@Html.MyEditFor</code> is called for <code>model.Age</code>.</p>
  
  <pre><code> @Html.MyEditFor(model=&gt;model.Age) 
  </code></pre>
  
  <p>But it not occures when <code>@Html.MyEditFor</code> is called for <code>model.EmpName</code> and <code>model.Email</code>.
  That's because <code>model.EmpName</code> and <code>model.Email</code> are strings but <code>model.Age</code> is <code>int</code></p>