title: Most efficient way to render data into a form from a populated model
body: <p>I've got a populated entity filled with checkbox selector, few strings. that has to be built linearly(for each row) in a loop in a div structure.</p>
  
  <p>The entity:</p>
  
  <pre><code>public class Hours
  {
     [Key] 
     public int SliceID { get; set; }
     public string SliceName { get; set; }
     public string Slice { get; set; } 
     public string StartTime { get; set; }
     public string EndTime { get; set; }
     public bool Selected { get; set; } //if slice is checked by user on search screen
  }
  </code></pre>
  
  <p>The action which will gather all time slices for display:</p>
  
  <pre><code>public ActionResult Search_Times()
  {
      int iInstId = 1;
  
      Test.Models.DataLayer db = new Test.Models.DataLayer();
      Test.Models.TestDB context = new Models.TestDB();
  
      IEnumerable&lt;Test.Models.Hours&gt; lst = db.GetSlices(context, iInstId).OrderBy(a =&gt; a.SliceID);
   //   ViewBag.SliceList = lst;
      return View(lst);
  
  }
  </code></pre>
  
  <p>I want to render those fields in a specific part of my body page along with some class/div formatting along the way.</p>
  
  <p>For example, If I use EditorForModel : </p>
  
  <p>in Main page:</p>
  
  <pre><code>@model IEnumerable&lt;Test.Models.Hours&gt;
  @Html.EditorForModel()
  </code></pre>
  
  <p>in the Hours EditorTemplate:</p>
  
  <pre><code>@model Test.Models.Hours
  &lt;div&gt;
      @Html.CheckBoxFor(
          x =&gt; x.Selected, 
          new { 
              @class = "jcf-unselectable",
              id = HtmlHelper.GenerateIdFromName("cb_slice." + ViewData.TemplateInfo.GetFullHtmlFieldName(""))
          }
      )
  // this should be a label too, made for example to show text from data.
          @Html.DisplayTextFor(x =&gt; x.SliceName)
  
  
  
      @Html.LabelFor(
      x=&gt; x.StartTime,
          new { 
              @class = "info"
  
          })
  
      @Html.LabelFor(
      x =&gt; x.EndTime, 
          new { 
              @class = "info"
  
          })
  
  &lt;/div&gt;
  </code></pre>
  
  <p>The @Html.LabelFor in my case will only show the row's title and not the data (for="" in the source view after rendering), Unlike DisplayTextFor which will show the data but is only a generic text.</p>
  
  <p>I need a way or to fix this current way, To manipulate the data from the model accordingly, Labels will show the data behind their field and I could generate the class,id needed(based on css/html required) inside that label in a loop.</p>
  
  <p>What's the best way to do so, viewbags/templates/etc? </p>