Mvc report
06.12.2016 - 09:59
Merhabalar mvc rapor konusunda
acil yardımcı olursanız sevinirim
8
Görüntülenme
0 Beğeni
Merhaba Yücel Aydemir,
İşini görmesi dileğiyle :)
using System.Collections.Generic;
using System.Linq;
namespace RDLC.Models
{
public class Customer
{
public static List<RDLC.Models.Customers> GetAllCustomers()
{
var entities = new NorthwindEntities1();
var x = from c in entities.Customers
select c;
return x.ToList();
}
}
}
using System.Web.Mvc;
namespace RDLC.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
string welcomeMessage = "Northwind Müşteri Listesine Hoşgeldiniz";
return View((object)welcomeMessage);
}
}
}
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<string>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Index</title>
</head>
<body>
<div>
<h2>
<%=Html.Encode(Model) %></h2>
<%=Html.ActionLink("Müşteri Listesi (PDF)","DetailsReport","Customers") %>
</div>
</body>
</html>
using System.Web.Mvc;
using Microsoft.Reporting.WebForms;
using RDLC.Models;
namespace RDLC.Controllers
{
public class CustomerController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult DetailsReport()
{
LocalReport localReport = new LocalReport();
localReport.ReportPath = Server.MapPath("~/Content/Reports/CustomerReport.rdlc");
ReportDataSource reportDataSource = new ReportDataSource("Customers", Customer.GetAllCustomers());
localReport.DataSources.Add(reportDataSource);
string reportType = "PDF";
string mimeTpe;
string encoding;
string fileNameExtension;
string deviceInfo = "<DeviceInfo>" +
" <OutputFormat>PDF</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 = localReport.Render(
reportType,
deviceInfo,
out mimeTpe,
out encoding,
out fileNameExtension,
out streams,
out warnings);
// Oluşan rapor sayfa içerisinde görüntülenmek isteniyorsa aşağıdaki kod parçası kapalı olmalıdır. Eğer ki ayrı bir sayfada
// görüntülenmek istiyorsanız ise kod parçasını açmanız gerekmektedir.
//Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
return File(renderedBytes, mimeTpe);
}
}
}