【发布时间】:2015-10-03 12:40:03
【问题描述】:
我在一个大学项目中使用 Asp.net MVC 5 和 EF 6。我正在使用 RDLC 来生成报告。
我创建了一个显示项目及其相关详细信息的简单报告。但我不知道如何显示项目的制造商名称而不是其制造商 ID。
谁能帮我解决这个问题?
已经这么多天了,我还在为报告而苦恼。看起来,使用 webforms 和 ADO.net 很容易。但是我发现很难使用实体框架将报表合并到 MVC 中。
如果有更好的选择,请告诉我。
对于这份报告,我参考了 this tutorial。
这是我生成报告的代码:
public ActionResult Report(string id)
{
LocalReport lr = new LocalReport();
string path = Path.Combine(Server.MapPath("~/Reports"), "Report_item.rdlc");
if (System.IO.File.Exists(path))
{
lr.ReportPath = path;
}
else
{
return View("Index");
}
List<Item> cm = new List<Item>();
cm = db.Items.ToList();
ReportDataSource rd = new ReportDataSource("MyData_Item", cm);
lr.DataSources.Add(rd);
string reportType = id;
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + id + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
物品型号:
public class Item
{
public int ID { get; set; }
[Required]
[Display(Name="Item")]
public string Name { get; set; }
[Display(Name="Generic Name")]
public int? DrugGenericNameID { get; set; }
[Display(Name = "Manufacturer")]
public int? ManufacturerID { get; set; }
[Display(Name = "Categeory")]
public Categeory? Categeory { get; set; }
public int AlertQty { get; set; }
public string Description { get; set; }
[Display(Name = "Last Update")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? LastUpdated { get; set; }
//reference entity
public virtual DrugGenericName DrugGenericName { get; set; }
public virtual Manufacturer Manufacturer { get; set; }
public virtual ICollection<Stock> Stocks { get; set; }
public virtual ICollection<PurchaseItem> PurchaseItems { get; set; }
}
public enum Categeory
{
Drug,
Supplies,
other
}
这是我的报告。如何派生关联名称而不是其 ID?
【问题讨论】:
-
你能用表格/字段发布你的数据源的表示吗?
-
为了更清晰,我添加了模型和报告图像。希望对您有所帮助。
标签: asp.net-mvc-4 visual-studio-2013 entity-framework-6 rdlc