title: ASP.NET MVC 5 Html.EditorFor and property of type object
body: <p>I am creating a dynamic user control in MVC 5 application. My view model looks like this:</p>
  
  <pre><code>public class StoredProceduerParametersRecordViewModel
  {
      public string ProcedureName { get; set; }
      public string ParameterName { get; set; }
      public string ServerName { get; set; }
      public object ParameterValue { get; set; }
      //public object NewParameterName { get; set; }
  }
  </code></pre>
  
  <p>The NewParameterName could be an int, string, bool or any data type.</p>
  
  <p>I am getting the NewParameterName values from Stored Procedure Parameters</p>
  
  <pre><code>List&lt;StoredProcedureParameter&gt; parameters = new List&lt;StoredProcedureParameter&gt;();
  parameters = database.StoredProcedures[procedure.ProcedureName]
                       .Parameters.OfType&lt;StoredProcedureParameter&gt;()
                       .ToList();
  
  foreach (var param in parameters)
  {
      StoredProceduerParametersRecordViewModel obj_parameter =
      new StoredProceduerParametersRecordViewModel();
  
      obj_parameter.ParameterName = param.Name;
      obj_parameter.NewParameterName = CommonHelper.ConvertSmoToClsType(param.DataType.SqlDataType, string.Empty);
      stored_procedure_parameters_list.Add(obj_parameter);
   }
  </code></pre>
  
  <p>My CommonHelper.ConvertSmoToClsType looks like this:</p>
  
  <pre><code>public static object ConvertSmoToClsType(SqlDataType dataType, string currentValue)
  {
     object Object = new object();
  
     switch (dataType)
     {
         case SqlDataType.BigInt:
         Object = (String.IsNullOrEmpty(currentValue)) ? (Int64)0 : Int64.Parse(currentValue);
         break;
         case SqlDataType.Bit:
         Object = (String.IsNullOrEmpty(currentValue)) ? (Boolean)false : Boolean.Parse(currentValue);
         break;
         case SqlDataType.Char:
         case SqlDataType.VarChar:
         case SqlDataType.VarCharMax:
         Object = (String.IsNullOrEmpty(currentValue)) ? String.Empty : currentValue;
         break;
         case SqlDataType.Real:
         case SqlDataType.Numeric:
         case SqlDataType.Float:
         Object = (String.IsNullOrEmpty(currentValue)) ? 0D : Double.Parse(currentValue);
         break;
         and so on...
      }
  }
  </code></pre>
  
  <p>I am trying to use HTML.Editor to display user controls</p>
  
  <pre><code>@foreach (var obj in Model.List_StoredProceduresParametersRecords_ViewModel)
  {
    &lt;tr id="@obj.ParameterName"&gt;
        &lt;td class="parameterName" data-value="@obj.ParameterName"&gt;@obj.ParameterName&lt;/td&gt;
        &lt;td&gt;@Html.Editor("NewParameterName")&lt;/td&gt;
    &lt;/tr&gt;
  }
  </code></pre>
  
  <p>I referenced my code using this link ---> <a href="https://stackoverflow.com/questions/6837059/asp-net-mvc3-html-editorfor-and-property-of-type-object">ASP.NET MVC3 Html.EditorFor and property of type object</a>
  However, this solutions is not applicable for list.</p>
  
  <p>How can I show the controls using Html.Editor or Html.EditorFor in my foreach loop?</p>