title: Export to excel using nested List
body: <p>I want to export my model to excel</p>
  
  <h2>Model</h2>
  
  <pre><code>public class CaseModel
  {
      public int CaseId { get; set; }
      public long TenantId { get; set; }
      public string CaseDescription { get; set; }        
      public List&lt;CustomFields&gt; CustomFields { get; set; }       
      public List&lt;CustomFieldForUsers&gt; CustomFieldForUser { get; set; }
  }
  </code></pre>
  
  <p>I am getting predefined fields in excel  but i am not getting <code>list</code> objects i.e <code>CustomFields</code> and <code>CustomFieldForUser</code></p>
  
  <h2>Controller</h2>
  
  <pre><code>public void ExportAsExcel()
  {
      List&lt;CaseModel&gt; lst = new List&lt;CaseModel&gt;();
      if (Request.QueryString["caseids"] != null)
      {
          string[] collection = Request.QueryString["caseids"].Split(',');
          foreach (var item in collection)
          {
              var model = caseservice.getCase(Tenant.Id, int.Parse(item));
              model.CustomFieldForUser = caseservice.getCustomFieldsForUser(Tenant.Id, int.Parse(item));
              model.CustomFields = caseservice.getCustomFields(Tenant.Id);
              lst.Add(model);
          }
      }
      var result = lst.Select(x =&gt; new
      {
          x.RefId,
          x.CaseDescription,
          x.CreatedBy,
          CreatedDate = String.Format("{0:MMM d, yyyy}", x.CreatedDate),
          CaseStatus = Enum.GetName(typeof(CaseStatus), x.CaseStatus),
          CasePriority = Enum.GetName(typeof(CasePriority), x.CasePriority),
          AssignedTo = x.AssignedTo == null || x.AssignedTo == "0" ? "NA" : tenantservice.getTenantUserById(Tenant.Id, x.AssignedTo).RealName,
          Company = x.CompanyId == 0 ? "NA" : companydetailservice.getCompanyDetails(Tenant.Id, x.CompanyId).Name,
  
         **//How to get the List objects here to be downloaded in excel since they are dynamic based on user who has loggedin**
  
      });
  
  
      GridView gv = new GridView();
      gv.DataSource = result;
      gv.DataBind();
      Response.ClearContent();
      Response.Buffer = true;
      Response.AddHeader("content-disposition", "attachment; filename=" + Tenant.SubDomain + "_Cases_" + DateTime.Now.ToShortDateString() + ".xls");
      Response.ContentType = "application/ms-excel";
      Response.Charset = "";
      StringWriter sw = new StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      gv.RenderControl(htw);
      Response.Output.Write(sw.ToString());
      Response.Flush();
      Response.End();
  }
  </code></pre>