using CrystalDecisions.CrystalReports.Engine;
using CrystalReportDemo.Models;
using System; using System.Collections.Generic;
using System.IO; using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CrystalReportDemo.Controllers
{
public class HomeController : Controller
{
MVCTutorialEntities db = new MVCTutorialEntities();
public ActionResult EmployeeList()
{
return View(db.EmployeeInfoes.ToList());
}
public ActionResult exportReport()
{
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Report"), "CrystalReport.rpt"));
rd.SetDataSource(db.EmployeeInfoes.ToList());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
try
{
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "Employee_list.pdf");
}
catch
{
throw;
}
}
}
}
@model IEnumerable<CrystalReportDemo.Models.EmployeeInfo>
@{
ViewBag.Title = "EmployeeList";
}
<h2>EmployeeList</h2>
<p>
<a class="btn btn-success" href="@Url.Action("exportReport")">Download Report</a>
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EmployeeId)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeName)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Phone)
</th>
<th>
@Html.DisplayNameFor(model => model.Experience)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmployeeId)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Experience)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}文章来源:https://www.toymoban.com/news/detail-432775.html
</table>文章来源地址https://www.toymoban.com/news/detail-432775.html
到了这里,关于Crystal Report 水晶报表实例MVC的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!