.NET导出为ex​​cel – 子行不显示

在我的asp.net应用程序中,我让用户通过点击button从视图中导出一些数据。 下面的代码导出一个excel文件。 问题是,我无法弄清楚如何显示对象的模型列表。

var grid = new GridView(); grid.DataSource = exportModels; grid.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=Exported_Orders.xls"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); 

数据源模型是这样的:

 public class ExportOrdersViewModel { public int Id { get; set; } public string CustomerFirstName { get; set; } public string CustomerLastName { get; set; } public string CustomerEmail { get; set; } public string CustomerMobile { get; set; } public string ShippingStreet { get; set; } public string ShippingCity { get; set; } public string ShippingCountry { get; set; } public string ShippingPostalCode { get; set; } public string ShippingTo { get; set; } public bool IsShipped { get; set; } public ICollection<ExportOrdersItemViewModel> Items { get; set; } } public class ExportOrdersItemViewModel { public string TicketName { get; set; } public string EventName { get; set; } public int Quantity { get; set; } public string CurrencyId { get; set; } public string PaymentCurrencyId { get; set; } public string UnitPrice { get; set; } public string PaymentUnitPrice { get; set; } } 

ExportOrderViewModel包含ExportOrderItemViewModel的列表,当文件被导出时,每个订单的项目行都缺less该文件的forms。 我真的需要一些帮助,如何在导出时添加这些字段。

这里是导出文件的标题:

在这里输入图像描述

这就是在创buildexcel文件之前网格对象包含的内容: enter image description here