title: Asp.Net MVC 3 Editor for dynamic property
body: <p>We have been trying to get the Editor-Template to work with a dynamic property - to no avail. Maybe one of you can help us.</p>
  
  <p>Here is roughly our class:</p>
  
  <pre><code>public class Criterion
  {
      ...
      public string Text { get; set; }
      public dynamic Value { get; set; }
      public Type Type { get; set; }
      ...
  }
  </code></pre>
  
  <p>Our razor view gets a model containg a list of sections which each contains a list of criteria in it. (We get these infos at runtime.) All these criteria should be displayed in edit mode - regarding their actual type: (excerpt)</p>
  
  <pre><code>@for (int i = 0; i &lt; model.Sections.Count(); i++)
  {
      for (int j = 0; j &lt; model.Sections[i].Criteria.Count(); j++)
      {
          var criterion = model.Sections[i].Criteria[j];
          var type = criterion.Type.Name;
          var name = "Sections[" + i + "].Criteria[" + j + "].Value";
          var criterionDisplayName = criterion.Text;
          &lt;label for="Sections_@(i)__Criteria_@(j)__Value"&gt;@criterionDisplayName&lt;/label&gt;
          @Html.Editor(name, type)
      }
  }
  </code></pre>
  
  <p>This does display for instance a checkbox correctly, but it does not use the value to set the checkbox status correctly (checked if the criterion.Value is true). Same goes for other types, like <code>ints</code>.
  (It does fill the form correctly after a POST request, but that is because MVC uses a temporary model to recreate the users input.)</p>
  
  <p>As much as we have tried and researched: Is it even possible to use the Editor template with properties of type <code>dynamic</code>? If yes - how can we make it work? (We would not like to discern according to the possible type. We would like to have the MVC framework to use the right Editor template based on the actual type.)</p>